/* ============================================================
   ROOT VARIABLES
   ============================================================ */
:root {
  --blue-primary:  #4d9dcb;
  --blue-dark:     #397597;
  --blue-link:     #1d6e9c;
  --tab-inactive:  #e8e8e8;
  --tab-active:    #4d9dcb;
  --border:        #c8c8c8;
  --sidebar-bg:    #fafafa;
  --body-bg:       #ffffff;
  --entry-bg:      #f0f0f0;
  --msg-highlight: #fff3da;
  --text-main:     #1a1a1a;
  --text-muted:    #666666;
  --system-join:   #1a7a3a;
  --system-leave:  #8a2020;
  --sidebar-w:     200px;
  --header-h:      32px;
  --tabs-h:        32px;
}

/* ============================================================
   RESET
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text-main);
  background: var(--body-bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue-link); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* ============================================================
   APP
   ============================================================ */
.app {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  height: var(--header-h);
  flex-shrink: 0;
  background: linear-gradient(135deg, #4d9dcb 0%, #3a84ad 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  z-index: 50;
  position: relative;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.brand-menu {
  display: flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #fff;
  font: bold 14px 'Segoe UI', Arial, sans-serif;
  padding: 0 8px;
  border-radius: 3px;
  height: var(--header-h);
  letter-spacing: .5px;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.brand-menu:hover { background: rgba(255,255,255,.15); }
.brand-name { font-size: 13px; }
.caret { font-size: 9px; opacity: .9; }

.topbar-right { display: flex; align-items: center; gap: 8px; }

.conn-status {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #aaa;
  border: 1.5px solid rgba(255,255,255,.6);
  flex-shrink: 0;
  transition: background .3s;
}
.conn-status.connected    { background: #6de06b; box-shadow: 0 0 5px rgba(109,224,107,.8); }
.conn-status.disconnected { background: #e05555; }
.conn-status.connecting   { background: #f0b020; animation: pulse .8s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }

.account-menu {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: none; cursor: pointer;
  color: #fff; font: 12px 'Segoe UI', Arial, sans-serif;
  padding: 3px 8px; border-radius: 3px; white-space: nowrap;
}
.account-menu:hover { background: rgba(255,255,255,.15); }

.avatar-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #aaa;
  border: 1.5px solid rgba(255,255,255,.7);
  flex-shrink: 0;
  transition: background .3s;
}
.avatar-dot.online { background: #6de06b; box-shadow: 0 0 4px rgba(109,224,107,.7); }
.account-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 600; }

.online-toggle {
  display: none; align-items: center; gap: 5px;
  background: transparent; border: none; color: #fff;
  font: 12px 'Segoe UI', Arial, sans-serif;
  cursor: pointer; padding: 3px 8px; border-radius: 3px;
}
.online-toggle:hover { background: rgba(255,255,255,.15); }
.online-toggle-dot { width: 7px; height: 7px; border-radius: 50%; background: #6de06b; }

/* ============================================================
   DROPDOWN MENUS
   ============================================================ */
.dropdown-menu {
  display: none;
  position: absolute;
  top: var(--header-h);
  left: 8px;
  min-width: 180px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
  z-index: 200;
  list-style: none;
  overflow: hidden;
}
.dropdown-menu.account-drop { right: 8px; left: auto; }
.dropdown-menu.open { display: block; }
.dropdown-menu li { border-bottom: 1px solid #f0f0f0; }
.dropdown-menu li:last-child { border-bottom: none; }
.dropdown-menu li a,
.dropdown-menu li button {
  display: block; width: 100%;
  padding: 9px 16px;
  font: 13px 'Segoe UI', Arial, sans-serif;
  color: var(--text-main); text-align: left;
  background: transparent; border: none; cursor: pointer; text-decoration: none;
}
.dropdown-menu li a:hover,
.dropdown-menu li button:hover { background: #f0f6fb; color: var(--blue-primary); }

/* Context Menu for Username Click */
.user-context-menu {
  position: absolute;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 22px rgba(0,0,0,0.22);
  z-index: 1000;
  min-width: 150px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: menuFadeIn 0.12s ease-out;
}
@keyframes menuFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
.user-context-menu button {
  background: transparent;
  border: none;
  padding: 10px 16px;
  font: 600 13px 'Segoe UI', Arial, sans-serif;
  text-align: left;
  cursor: pointer;
  color: var(--text-main);
  transition: background .1s, color .1s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-context-menu button:hover {
  background: #f0f6fb;
  color: var(--blue-primary);
}
.user-context-menu .menu-sep {
  height: 1px;
  background: #f0f0f0;
}

/* ============================================================
   TABS
   ============================================================ */
.tabs {
  height: var(--tabs-h);
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  background: var(--tab-inactive);
  border-bottom: 2px solid var(--blue-primary);
  padding-left: 6px;
  gap: 2px;
  overflow-x: auto;
}
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 14px;
  height: 28px;
  font: 600 13px 'Segoe UI', Arial, sans-serif;
  cursor: pointer; border: 1px solid transparent;
  border-bottom: none; border-radius: 4px 4px 0 0;
  background: var(--tab-inactive); color: #555;
  white-space: nowrap; transition: background .15s;
}
.tab.active {
  background: #fff;
  border-color: var(--blue-primary);
  color: var(--blue-primary);
  position: relative;
  top: 2px;
  z-index: 2;
}
.tab:hover:not(.active) { background: #ddd; }

/* Unread notification badge for PM tabs */
.tab.unread-tab {
  background: #ffebeb;
  color: #cc0000;
  border-color: #ffcccc;
  animation: tabPulse 1.5s infinite;
}
@keyframes tabPulse {
  0%, 100% { box-shadow: inset 0 0 0 rgba(204,0,0,0); }
  50% { box-shadow: inset 0 0 10px rgba(204,0,0,.15); }
}

/* PM tab close button */
.pm-tab-close {
  background: transparent; border: none; cursor: pointer;
  font-size: 11px; color: #999; padding: 0 2px;
  border-radius: 2px; line-height: 1;
  margin-left: 2px;
}
.pm-tab-close:hover { background: rgba(0,0,0,.08); color: #c00; }

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
.main-layout {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* ============================================================
   TAB PANELS WRAP
   ============================================================ */
.tab-panels-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  overflow: hidden;
}

.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.tab-panel.active { display: flex; }

/* ============================================================
   OBSERVER NOTICE
   ============================================================ */
.observer-notice {
  flex-shrink: 0;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  background: #e8f4fb;
  border-bottom: 1px solid #b8d8ee;
  font-size: 12px;
  color: #1d5c80;
}
.observer-notice a { font-weight: 700; color: var(--blue-primary); text-decoration: underline; }

/* ============================================================
   MESSAGES AREA
   ============================================================ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 8px 8px;
  min-height: 0;
  background: #fff;
}
.messages::-webkit-scrollbar { width: 7px; }
.messages::-webkit-scrollbar-track { background: #f4f4f4; }
.messages::-webkit-scrollbar-thumb { background: #c0c0c0; border-radius: 6px; }
.messages::-webkit-scrollbar-thumb:hover { background: #a0a0a0; }

/* ── Regular message ── */
.msg {
  display: flex;
  gap: 10px;
  padding: 5px 6px;
  border-radius: 4px;
  word-wrap: break-word;
  border-bottom: 1px solid #f4f4f4;
  transition: background .1s;
}
.msg:last-child { border-bottom: none; }
.msg:hover { background: #f7f9fb; }
.msg.highlighted { background: var(--msg-highlight) !important; border-left: 3px solid #e8a000; }

/* Avatar */
.msg-avatar { width: 36px; flex-shrink: 0; padding-top: 2px; }
.avatar-img {
  width: 36px; height: 44px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font: bold 13px 'Segoe UI', Arial, sans-serif;
  color: #fff; user-select: none;
  box-shadow: 0 2px 5px rgba(0,0,0,.18);
  letter-spacing: .5px;
}

/* Message content */
.msg-content { flex: 1; min-width: 0; }
.msg-header  { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; }

/* USERNAME — prominent */
.msg .username {
  font: bold 15px 'Segoe UI', Arial, sans-serif;
  cursor: pointer;
  letter-spacing: .2px;
}
.msg .username:hover { text-decoration: underline; opacity: .85; }

/* Role badge next to username */
.msg .role-badge {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 700;
  letter-spacing: .3px;
}
.role-badge.admin { background: #cc6600; color: #fff; }
.role-badge.mod   { background: #8844bb; color: #fff; }
.role-badge.guest { background: #999; color: #fff; font-weight: 500; }
.role-badge.bot   { background: #00aa66; color: #fff; font-weight: 500; }

.msg .timestamp { font-size: 10px; color: var(--text-muted); white-space: nowrap; margin-left: auto; }

/* Message body */
.msg .body {
  display: block;
  font-size: 14px;
  color: #222;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

/* Markup styles in messages */
.msg .body strong { font-weight: 700; }
.msg .body em     { font-style: italic; }
.msg .body s      { text-decoration: line-through; }
.msg-h1 { display: block; font: bold 22px 'Segoe UI', Arial, sans-serif; line-height: 1.2; margin: 2px 0; }
.msg-h2 { display: block; font: bold 18px 'Segoe UI', Arial, sans-serif; line-height: 1.2; margin: 2px 0; }
.msg-h3 { display: block; font: bold 15px 'Segoe UI', Arial, sans-serif; line-height: 1.2; margin: 2px 0; }
.mc-blue   { color: #4d9dcb; }
.mc-pink   { color: #d468b0; }
.mc-green  { color: #1f9d55; }
.mc-red    { color: #cc0000; }
.mc-orange { color: #cc6600; }
.mc-purple { color: #8844bb; }
.mc-gold   { color: #c8a000; }

/* @mentions */
.mention {
  color: var(--blue-primary);
  font-weight: 700;
  cursor: pointer;
  background: rgba(77,157,203,.1);
  border-radius: 3px;
  padding: 0 2px;
}
.mention:hover { text-decoration: underline; }

/* Golden Admin branding */
.admin-gold {
  color: #c99300 !important; /* Rich Dark Gold */
  font-weight: 800 !important;
  text-shadow: 0 1px 2px rgba(0,0,0,0.12);
}
.admin-avatar {
  background: linear-gradient(135deg, #ffd700 0%, #b8860b 100%) !important;
  box-shadow: 0 2px 6px rgba(184,134,11,0.45) !important;
  border: 1.5px solid #ffd700 !important;
}
.bot-avatar {
  background: linear-gradient(135deg, #00ee88 0%, #008855 100%) !important;
  box-shadow: 0 2px 6px rgba(0,136,85,0.45) !important;
  border: 1.5px solid #00ee88 !important;
}

/* Gender Badges */
.gender-badge {
  font-weight: 900;
  margin-left: 5px;
  font-size: 13px;
  display: inline-block;
  vertical-align: middle;
}
.gender-badge.male   { color: #4d9dcb !important; }
.gender-badge.female { color: #d468b0 !important; }

/* ── System messages (join/leave) ── */
.msg.system {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 4px;
  margin: 2px 0;
  border-left: 3px solid transparent;
  font-size: 13px;
  font-weight: 500;
  border-bottom: none;
}
.msg.system:hover { background: transparent !important; }

.msg.system-join {
  background: rgba(26,122,58,.07);
  border-left-color: var(--system-join);
  color: var(--system-join);
}
.msg.system-leave {
  background: rgba(138,32,32,.07);
  border-left-color: var(--system-leave);
  color: var(--system-leave);
}
.msg.system-notice {
  background: rgba(77,157,203,.07);
  border-left-color: var(--blue-primary);
  color: #1d5c80;
}
.msg.system-admin {
  background: rgba(204,102,0,.07);
  border-left-color: #cc6600;
  color: #8a4400;
}
.sys-icon { font-size: 15px; flex-shrink: 0; }
.sys-body { flex: 1; }
.sys-time { font-size: 10px; color: var(--text-muted); white-space: nowrap; }

/* ── PM messages ── */
.msg.pm-received {
  background: #e8f4fb;
  border-left: 3px solid var(--blue-primary);
  padding: 6px 10px;
  border-radius: 0 6px 6px 0;
}
.msg.pm-sent {
  background: #f0ffe8;
  border-left: 3px solid #1f9d55;
  padding: 6px 10px;
  border-radius: 0 6px 6px 0;
}
.pm-label { font-weight: 700; font-size: 12px; }
.msg.pm-received .pm-label { color: var(--blue-primary); }
.msg.pm-sent .pm-label     { color: #1a7a3a; }

/* Username color palette */
.c1 { color: #4d9dcb; }
.c2 { color: #d468b0; }
.c3 { color: #1f9d55; }
.c4 { color: #cc6600; }
.c5 { color: #8844bb; }
.c6 { color: #cc0000; }

/* Guest marker */
.guest-mark { font-size: 10px; color: #999; font-style: italic; }

/* Scroll-to-bottom */
.scroll-bottom-btn {
  display: none;
  position: absolute;
  bottom: 10px; right: 16px;
  background: #fff;
  border: 1px solid #c8c8c8;
  border-radius: 20px;
  font-size: 12px;
  padding: 5px 14px;
  cursor: pointer;
  color: var(--blue-link);
  box-shadow: 0 3px 10px rgba(0,0,0,.15);
  z-index: 5;
  font-weight: 600;
  transition: box-shadow .15s;
}
.scroll-bottom-btn.visible { display: flex; align-items: center; gap: 5px; }
.scroll-bottom-btn:hover { box-shadow: 0 4px 14px rgba(0,0,0,.22); }

/* ============================================================
   RULES TOGGLE BAR
   ============================================================ */
.rules-toggle-bar {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 12px;
  background: #f0f4f8;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.rules-toggle-label { font-weight: 700; color: #444; }
.rules-toggle-btn {
  background: var(--blue-primary); color: #fff;
  border: none; border-radius: 4px; padding: 3px 12px;
  font: 600 11px 'Segoe UI', Arial, sans-serif;
  cursor: pointer; transition: background .15s;
}
.rules-toggle-btn:hover { background: var(--blue-dark); }

/* ============================================================
   RULES PANEL
   ============================================================ */
.rules-panel {
  padding: 12px 14px;
  font-size: 13px; color: #333;
  overflow-y: auto; flex-shrink: 0;
  max-height: 32%; background: #fafcfe;
  border-bottom: 1px solid var(--border);
  transition: max-height .3s ease, padding .3s ease, opacity .25s ease;
  opacity: 1;
}
.rules-panel.collapsed { max-height: 0 !important; padding-top: 0; padding-bottom: 0; overflow: hidden; opacity: 0; }
.rules-panel::-webkit-scrollbar { width: 5px; }
.rules-panel::-webkit-scrollbar-thumb { background: #c8c8c8; border-radius: 3px; }
.rules-welcome { margin-bottom: 8px; line-height: 1.6; }
.rw-big    { color: #cc0000; font-weight: 700; }
.rw-little { color: #cc6600; font-weight: 700; }
.rw-ab     { color: #1d6e9c; font-weight: 700; }
.rw-dl     { color: #1a7a3a; font-weight: 700; }
.rules-list { margin: 0 0 8px 22px; line-height: 1.7; }
.rules-list li { margin-bottom: 3px; }
.rules-footer { color: #666; font-size: 12px; margin-top: 8px; line-height: 1.6; }

/* ============================================================
   ENTRY BAR
   ============================================================ */
.entry-bar {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  height: 46px;
  border-top: 2px solid var(--border);
  background: var(--entry-bg);
}
.enter-btn {
  background: var(--blue-primary);
  color: #fff;
  border: none; border-radius: 4px;
  padding: 7px 18px;
  font: 600 13px 'Segoe UI', Arial, sans-serif;
  cursor: pointer; transition: background .15s;
}
.enter-btn:hover { background: var(--blue-dark); }
.more-link { font-size: 12px; color: var(--blue-link); }

/* ============================================================
   FORMAT TOOLBAR
   ============================================================ */
.format-toolbar {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: 4px 10px;
  background: #f4f6f8;
  border-top: 1px solid var(--border);
}
.fmt-btn {
  min-width: 28px; height: 26px;
  background: #fff;
  border: 1px solid #c8c8c8;
  border-radius: 4px;
  font: 13px 'Segoe UI', Arial, sans-serif;
  cursor: pointer;
  color: #333;
  padding: 0 6px;
  transition: background .12s, border-color .12s;
}
.fmt-btn:hover   { background: #e8f0f8; border-color: var(--blue-primary); color: var(--blue-primary); }
.fmt-btn:active  { background: #d0e4f4; }
.fmt-bold   { font-weight: 800; font-size: 14px; }
.fmt-italic { font-style: italic; font-size: 13px; }
.fmt-strike { text-decoration: line-through; font-size: 13px; }
.fmt-h1     { font-size: 11px; font-weight: 700; }
.fmt-h2     { font-size: 10px; font-weight: 700; }
.fmt-h3     { font-size: 10px; font-weight: 600; }
.fmt-sep    { width: 1px; background: #c8c8c8; height: 20px; margin: 0 3px; }
.fmt-label  { font-size: 11px; color: #777; font-weight: 600; white-space: nowrap; }
.fmt-color {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.8);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  transition: transform .1s, box-shadow .1s;
  outline: none;
}
.fmt-color:hover  { transform: scale(1.18); box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.fmt-color:active { transform: scale(.95); }
.fmt-clear {
  margin-left: auto;
  background: transparent; border: 1px solid #c8c8c8;
  border-radius: 4px; padding: 2px 8px;
  font-size: 11px; color: #888; cursor: pointer;
}
.fmt-clear:hover { background: #fee; border-color: #e05555; color: #c00; }

/* ============================================================
   CHAT INPUT BAR
   ============================================================ */
.chat-input-bar {
  flex-shrink: 0;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px;
  border-top: 2px solid var(--border);
  background: var(--entry-bg);
  min-height: 70px;
}
.chat-input-wrap { flex: 1; min-width: 0; }
.chat-input {
  width: 100%;
  min-height: 55px; /* Larger min-height for easy typing and editing */
  max-height: 160px;
  border: 1.5px solid #b8b8b8;
  border-radius: 6px;
  font: 15px 'Segoe UI', Arial, sans-serif; /* Larger font */
  padding: 10px 14px; /* More padding */
  resize: none;
  outline: none;
  overflow-y: auto;
  background: #fff;
  color: var(--text-main);
  line-height: 1.5;
  transition: border-color .15s, box-shadow .15s;
}
.chat-input::placeholder { color: #aaa; font-style: italic; font-size: 13px; }
.chat-input:focus {
  border-color: var(--blue-primary);
  box-shadow: 0 0 0 3px rgba(77,157,203,.2);
}
.send-btn {
  flex-shrink: 0; width: 55px; height: 55px; /* Larger send button to match input height */
  background: var(--blue-primary);
  border: none; border-radius: 6px;
  cursor: pointer; color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .1s;
  align-self: flex-end;
  box-shadow: 0 2px 6px rgba(77,157,203,.4);
}
.send-btn:hover  { background: var(--blue-dark); }
.send-btn:active { transform: scale(.93); }

/* ============================================================
   PM ROOM PANEL
   ============================================================ */
.pm-panel {
  display: none;
  flex-direction: column;
  background: #fff;
}
.pm-panel.active { display: flex; }
.pm-panel-header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: linear-gradient(135deg, #4d9dcb, #3a84ad);
  color: #fff;
  font: 600 14px 'Segoe UI', Arial, sans-serif;
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
}
.pm-panel-header .pm-panel-user { display: flex; align-items: center; gap: 8px; }
.pm-panel-header .pm-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font: bold 12px 'Segoe UI', Arial; color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.pm-panel-title { font-size: 14px; font-weight: 700; }
.pm-panel-subtitle { font-size: 11px; opacity: .8; }
.pm-close-btn {
  background: rgba(255,255,255,.2); border: none;
  border-radius: 4px; color: #fff; cursor: pointer;
  padding: 4px 10px; font: 12px 'Segoe UI'; transition: background .15s;
}
.pm-close-btn:hover { background: rgba(255,255,255,.35); }

.pm-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  background: #f8fbfe;
}
.pm-messages::-webkit-scrollbar { width: 6px; }
.pm-messages::-webkit-scrollbar-thumb { background: #c0c0c0; border-radius: 3px; }

/* PM message bubbles */
.pm-bubble-wrap { display: flex; flex-direction: column; margin-bottom: 10px; }
.pm-bubble-wrap.pm-mine { align-items: flex-start; }
.pm-bubble-wrap.pm-theirs { align-items: flex-start; }
.pm-bubble {
  max-width: 75%;
  padding: 8px 14px;
  border-radius: 18px;
  font-size: 14px; line-height: 1.5;
  position: relative;
  word-wrap: break-word;
}
.pm-mine   .pm-bubble { background: var(--blue-primary); color: #fff; border-bottom-left-radius: 4px; }
.pm-theirs .pm-bubble { background: #e8e8e8; color: #222; border-bottom-left-radius: 4px; }
.pm-meta { font-size: 10px; color: #aaa; margin-top: 3px; padding: 0 4px; }
.pm-sender { font-size: 10px; font-weight: 700; margin-bottom: 2px; padding: 0 4px; }
.pm-mine .pm-sender { color: var(--blue-primary); text-align: left; }
.pm-theirs .pm-sender { color: #555; text-align: left; }

.pm-input-bar {
  flex-shrink: 0;
  display: flex; align-items: flex-end; gap: 8px;
  padding: 7px 10px;
  border-top: 2px solid var(--border);
  background: var(--entry-bg);
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--sidebar-bg);
  border-left: 1.5px solid var(--border);
}
.sidebar-header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 10px;
  border-bottom: 1.5px solid var(--border);
  background: linear-gradient(135deg, #f0f4f8, #e8eef4);
}
.sidebar-header-left { display: flex; align-items: center; gap: 7px; }
.online-dot-big {
  width: 10px; height: 10px; border-radius: 50%;
  background: #6de06b; flex-shrink: 0;
  box-shadow: 0 0 5px rgba(109,224,107,.7);
}
.sidebar-header strong { font-size: 13px; color: #333; }
.sidebar-header span   { font-size: 12px; color: #555; }
.sidebar-close {
  display: none;
  background: transparent; border: none; font-size: 16px;
  cursor: pointer; color: #888; padding: 0 3px; border-radius: 3px;
}
.sidebar-close:hover { color: #333; }

/* User list */
.user-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}
.user-list::-webkit-scrollbar { width: 5px; }
.user-list::-webkit-scrollbar-thumb { background: #c0c0c0; border-radius: 3px; }
.user-list-empty {
  padding: 20px 12px;
  font-size: 12px; color: #b0b0b0;
  text-align: center; font-style: italic;
}

/* User list section labels */
.user-group-label {
  padding: 5px 10px 3px;
  font: 700 10px 'Segoe UI', Arial, sans-serif;
  color: #999; text-transform: uppercase; letter-spacing: 1px;
  background: #f4f4f4;
  border-bottom: 1px solid #e8e8e8;
}

/* Individual user rows */
.user-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  transition: background .12s;
  position: relative;
}
.user-row:hover { background: #eef4fa; }
.user-row:last-child { border-bottom: none; }

/* User avatar in sidebar */
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font: bold 12px 'Segoe UI', Arial; color: #fff;
  flex-shrink: 0;
  position: relative;
  box-shadow: 0 2px 5px rgba(0,0,0,.18);
  transition: background .2s, box-shadow .2s;
}
.user-avatar::after {
  content: '';
  position: absolute;
  bottom: -1px; right: -1px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #6de06b;
  border: 1.5px solid #fff;
}
.user-info { flex: 1; min-width: 0; }
.user-row-name {
  font: 600 13px 'Segoe UI', Arial, sans-serif;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: block;
}
.user-row-sub {
  font-size: 10px; color: #999;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: block;
  margin-top: 1px;
}
.user-row-badge {
  font-size: 13px; flex-shrink: 0;
}

/* ============================================================
   MODAL BASE
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 300;
  align-items: center; justify-content: center;
  padding: 12px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 14px 50px rgba(0,0,0,.28);
  padding: 24px 28px 26px;
  width: 90%; max-width: 400px;
  max-height: 90vh; overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute; top: 12px; right: 14px;
  background: transparent; border: none; font-size: 20px;
  cursor: pointer; color: #aaa; line-height: 1;
}
.modal-close:hover { color: #333; }
.modal-title { font: bold 17px 'Segoe UI', Arial; margin-bottom: 6px; color: var(--text-main); }
.modal-hint  { font-size: 12px; color: #777; margin-bottom: 16px; }

/* Modal tabs */
.modal-tabs {
  display: flex; border-bottom: 2px solid var(--blue-primary);
  margin-bottom: 18px; gap: 0;
}
.modal-tab {
  flex: 1; padding: 8px 6px;
  font: 12px 'Segoe UI', Arial; cursor: pointer;
  border: 1px solid transparent; border-bottom: none;
  border-radius: 4px 4px 0 0;
  background: var(--tab-inactive); color: #666;
  text-align: center; transition: background .12s;
}
.modal-tab.active {
  background: #fff; border-color: var(--blue-primary);
  color: var(--blue-primary); font-weight: 700;
  margin-bottom: -2px;
}
.modal-pane { display: none; }
.modal-pane.active { display: block; }

/* Form rows */
.form-row { margin-bottom: 14px; }
.form-row label { display: block; font: 600 12px 'Segoe UI'; margin-bottom: 5px; color: #444; }
.form-row input,
.form-row select {
  width: 100%; height: 32px;
  border: 1.5px solid #c8c8c8; border-radius: 4px;
  font: 13px 'Segoe UI', Arial; padding: 0 10px;
  outline: none; color: var(--text-main); background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.form-row input:focus,
.form-row select:focus {
  border-color: var(--blue-primary);
  box-shadow: 0 0 0 3px rgba(77,157,203,.2);
}
.form-row-inline { display: flex; gap: 12px; }
.form-row-inline > div { flex: 1; }
.form-error { font-size: 12px; color: #d0000a; min-height: 16px; margin-bottom: 8px; font-weight: 600; }
.modal-btn {
  width: 100%; height: 36px;
  background: var(--blue-primary); color: #fff;
  border: none; border-radius: 4px;
  font: bold 13px 'Segoe UI', Arial; cursor: pointer;
  transition: background .15s;
}
.modal-btn:hover { background: var(--blue-dark); }
.modal-footer { text-align: center; margin-top: 14px; font-size: 12px; color: #666; }
.modal-footer a { color: var(--blue-link); }

/* ============================================================
   ADMIN MODAL
   ============================================================ */
.admin-modal-box { max-width: 900px; width: 96vw; padding: 18px 20px; }
.admin-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.admin-tab {
  padding: 5px 14px; font: 600 12px 'Segoe UI';
  border: 1px solid var(--border); border-radius: 4px 4px 0 0;
  background: var(--tab-inactive); cursor: pointer; color: #555;
}
.admin-tab.active { background: var(--blue-primary); color: #fff; border-color: var(--blue-dark); }
.admin-panel { display: none; }
.admin-panel.active { display: block; }
.admin-toolbar { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.admin-search {
  flex: 1; height: 30px; border: 1px solid #c8c8c8; border-radius: 4px;
  font: 13px 'Segoe UI'; padding: 0 10px; outline: none;
}
.admin-search:focus { border-color: var(--blue-primary); }
.admin-refresh-btn { padding: 5px 14px; background: var(--blue-primary); color: #fff; border: none; border-radius: 4px; font: 600 12px 'Segoe UI'; cursor: pointer; }
.admin-refresh-btn:hover { background: var(--blue-dark); }
.admin-table-wrap { overflow-x: auto; max-height: 55vh; overflow-y: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.admin-table th {
  background: #f0f4f7; border: 1px solid var(--border);
  padding: 7px 10px; text-align: left; font-weight: 700;
  position: sticky; top: 0; font-size: 12px;
}
.admin-table td {
  border: 1px solid #e8e8e8; padding: 6px 10px;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.admin-table tr:hover td { background: #f8f8f8; }
.admin-action-btn { padding: 3px 10px; border: none; border-radius: 3px; cursor: pointer; font: 600 11px 'Segoe UI'; margin-right: 4px; }
.admin-action-btn.ban   { background: #e05555; color: #fff; }
.admin-action-btn.unban { background: #1f9d55; color: #fff; }
.admin-action-btn.kick  { background: #f0a020; color: #fff; }
.banned-row td { color: #b00; opacity: .7; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) { :root { --sidebar-w: 170px; } }

@media (max-width: 860px) {
  .online-toggle { display: flex; }
  .sidebar {
    position: fixed; top: 0; right: 0;
    height: 100%; width: 280px !important; max-width: 82vw;
    z-index: 30; transform: translateX(100%);
    transition: transform .25s ease;
    box-shadow: -4px 0 20px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; }
  .sidebar-overlay.show { display: block; }
}

@media (max-width: 600px) {
  .account-name { display: none; }
  .tab { padding: 0 10px; font-size: 12px; }
  .messages { padding: 5px 7px; }
  .rules-panel { max-height: 28%; font-size: 12px; padding: 8px 10px; }
  .chat-input-bar { padding: 6px 8px; }
  .modal-box { padding: 16px 14px; }
  .admin-modal-box { width: 99vw; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .rules-panel, .modal-overlay { transition: none; }
}
