:root {
  --bg: #080d19;
  --panel: #10182b;
  --panel-2: #141f37;
  --panel-3: #0d1425;
  --line: #283653;
  --line-soft: rgba(255,255,255,.07);
  --text: #eef3ff;
  --muted: #9aa9c6;
  --accent: #6e8cff;
  --accent-2: #94a8ff;
  --success: #7be49d;
  --danger: #ff8f99;
  --shadow: 0 24px 70px rgba(0,0,0,.28);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
}

button, input {
  font: inherit;
}

button {
  color: inherit;
}

a {
  color: inherit;
}

.morphie-app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  background:
    radial-gradient(circle at top left, rgba(82,110,219,.12), transparent 32rem),
    var(--bg);
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 12px clamp(16px, 3vw, 38px);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(8,13,25,.9);
  backdrop-filter: blur(16px);
  position: relative;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  min-width: max-content;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 900;
  background: linear-gradient(135deg, #536fd9, #8d6ee8);
  box-shadow: 0 8px 30px rgba(93,113,223,.25);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong { letter-spacing: .02em; }
.brand small { color: var(--muted); font-size: .72rem; margin-top: 1px; }

.site-nav {
  display: flex;
  gap: 6px;
  flex: 1;
}

.site-nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 9px 11px;
  border-radius: 9px;
  font-size: .9rem;
}

.site-nav a:hover {
  color: var(--text);
  background: rgba(255,255,255,.05);
}

.connection-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: .82rem;
  white-space: nowrap;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #67748d;
}

.connection-pill[data-state="online"] .connection-dot { background: var(--success); box-shadow: 0 0 14px rgba(123,228,157,.55); }
.connection-pill[data-state="connecting"] .connection-dot { background: #ffd074; }
.connection-pill[data-state="error"] .connection-dot { background: var(--danger); }

.chat-shell {
  min-height: 0;
  display: grid;
  grid-template-columns: 270px minmax(0,1fr) 240px;
  height: calc(100vh - 72px);
}

.sidebar,
.members-panel {
  min-height: 0;
  background: rgba(14,22,40,.82);
  backdrop-filter: blur(16px);
}

.sidebar {
  border-right: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-head,
.members-head {
  padding: 22px 18px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.sidebar-head h1 {
  margin: 5px 0 0;
  font-size: 1.35rem;
}

.eyebrow {
  color: var(--accent-2);
  font-weight: 800;
  font-size: .68rem;
  letter-spacing: .12em;
}

.sidebar-section {
  padding: 10px 12px;
}

.section-title {
  padding: 4px 10px 9px;
  color: #8290ad;
  font-size: .7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .12em;
}

.room-button {
  width: 100%;
  display: grid;
  grid-template-columns: 36px minmax(0,1fr) auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: .15s ease;
}

.room-button:hover {
  background: rgba(255,255,255,.04);
}

.room-button.active {
  background: rgba(102,130,237,.13);
  border-color: rgba(110,140,255,.24);
}

.room-icon,
.channel-icon {
  display: grid;
  place-items: center;
}

.room-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,.045);
}

.room-button strong,
.room-button small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-button strong { font-size: .9rem; }
.room-button small { color: var(--muted); margin-top: 2px; font-size: .72rem; }

.unread-badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  border: 0;
  background: var(--accent);
  color: white;
  font-size: .7rem;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 15px;
  border-top: 1px solid var(--line-soft);
}

.nick-summary {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.nick-summary strong,
.nick-summary small {
  display: block;
}

.nick-summary small { color: var(--muted); font-size: .72rem; margin-top: 2px; }

.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-weight: 800;
  background: linear-gradient(135deg, #324982, #6c5faa);
}

.conversation {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: relative;
}

.conversation-head {
  min-height: 67px;
  border-bottom: 1px solid var(--line-soft);
  padding: 11px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(10,16,29,.72);
}

.channel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.channel-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: rgba(255,255,255,.045);
  font-size: 1.1rem;
}

.channel-title strong,
.channel-title small {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.channel-title small {
  color: var(--muted);
  font-size: .76rem;
  margin-top: 2px;
}

.head-actions {
  margin-left: auto;
}

.icon-button,
.small-button,
.primary-button,
.send-button {
  border: 0;
  cursor: pointer;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: transparent;
  display: grid;
  place-items: center;
}

.icon-button:hover { background: rgba(255,255,255,.06); }

.small-button {
  padding: 8px 10px;
  border-radius: 9px;
  background: rgba(255,255,255,.065);
  border: 1px solid var(--line-soft);
  font-size: .78rem;
}

.primary-button,
.send-button {
  background: linear-gradient(135deg, #506fd6, #6d69d5);
  color: white;
  font-weight: 800;
  border-radius: 11px;
}

.primary-button {
  padding: 12px 18px;
}

.send-button {
  padding: 0 18px;
}

.welcome-card {
  align-self: center;
  justify-self: center;
  width: min(610px, calc(100% - 34px));
  background: rgba(19,30,53,.92);
  border: 1px solid rgba(118,143,236,.2);
  border-radius: 22px;
  padding: clamp(22px,5vw,38px);
  box-shadow: var(--shadow);
}

.welcome-card h2 {
  margin: 8px 0 10px;
  font-size: clamp(1.55rem, 4vw, 2.3rem);
  line-height: 1.05;
}

.welcome-card p {
  color: #b8c5df;
  line-height: 1.65;
}

.join-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 24px;
}

.join-form label span {
  position: absolute;
  clip: rect(0 0 0 0);
}

.join-form input,
.composer input {
  width: 100%;
  border: 1px solid #354665;
  background: #0b1324;
  color: var(--text);
  outline: none;
}

.join-form input {
  min-height: 46px;
  border-radius: 11px;
  padding: 0 13px;
}

.join-form input:focus,
.composer input:focus {
  border-color: #6886e8;
  box-shadow: 0 0 0 3px rgba(104,134,232,.1);
}

.join-note {
  display: block;
  margin-top: 12px;
  color: #7f8da8;
  font-size: .7rem;
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 20px clamp(14px,3vw,28px);
  scroll-behavior: smooth;
}

.welcome-card:not([hidden]) + .messages {
  display: none;
}

.message {
  display: grid;
  grid-template-columns: 44px minmax(0,1fr);
  gap: 10px;
  padding: 8px 0;
}

.message + .message {
  border-top: 1px solid rgba(255,255,255,.018);
}

.message-avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #1c2c4d;
  color: #cbd7ef;
  font-size: .76rem;
  font-weight: 900;
}

.message-meta {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-bottom: 3px;
}

.message-nick {
  font-weight: 800;
  font-size: .89rem;
}

.message-time {
  color: #6f7d98;
  font-size: .68rem;
}

.message-text {
  color: #d7e0f3;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.message-text a {
  color: #9bb0ff;
}

.system-message {
  padding: 5px 4px 5px 54px;
  color: #74829d;
  font-size: .73rem;
}

.system-message.important {
  color: #a9b9db;
}

.composer-wrap {
  border-top: 1px solid var(--line-soft);
  padding: 12px 16px 10px;
  background: rgba(10,16,29,.75);
}

.composer {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 8px;
}

.composer input {
  height: 44px;
  border-radius: 11px;
  padding: 0 13px;
}

.typing-hint {
  color: #6f7d98;
  font-size: .67rem;
  padding: 6px 4px 0 48px;
}

.members-panel {
  border-left: 1px solid var(--line-soft);
  overflow-y: auto;
}

.members-head {
  align-items: center;
  border-bottom: 1px solid var(--line-soft);
}

.members-head strong {
  display: block;
  margin-top: 3px;
  font-size: .9rem;
}

.member-list {
  padding: 10px;
}

.member {
  display: flex;
  gap: 9px;
  align-items: center;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.member:hover {
  background: rgba(255,255,255,.04);
}

.member .avatar {
  width: 31px;
  height: 31px;
  font-size: .68rem;
}

.member-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .82rem;
}

.member-prefix {
  color: var(--accent-2);
  margin-right: 2px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 100;
  background: #202b45;
  border: 1px solid #354565;
  padding: 11px 15px;
  border-radius: 11px;
  box-shadow: var(--shadow);
  max-width: min(92vw, 520px);
  font-size: .82rem;
}

.menu-button,
.sidebar-close,
.members-close {
  display: none;
}

@media (max-width: 1050px) {
  .chat-shell { grid-template-columns: 250px minmax(0,1fr); }
  .members-panel {
    position: fixed;
    top: 72px;
    bottom: 0;
    right: 0;
    width: min(300px, 88vw);
    z-index: 40;
    transform: translateX(105%);
    transition: transform .2s ease;
    box-shadow: -24px 0 60px rgba(0,0,0,.3);
  }
  .members-panel.open { transform: translateX(0); }
  .members-close { display: grid; }
}

@media (max-width: 790px) {
  .site-nav { display: none; }
  .topbar { min-height: 64px; }
  .chat-shell {
    height: calc(100vh - 64px);
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 64px;
    bottom: 0;
    left: 0;
    width: min(310px, 90vw);
    z-index: 45;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 24px 0 60px rgba(0,0,0,.3);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close,
  .menu-button { display: grid; }
  .members-panel { top: 64px; }
  .connection-pill span:last-child { display: none; }
  .connection-pill { padding: 9px; }
  .join-form { grid-template-columns: 1fr; }
  .primary-button { min-height: 46px; }
}

@media (max-width: 520px) {
  .topbar { padding-inline: 12px; }
  .brand small { display: none; }
  .conversation-head { padding-inline: 10px; }
  .channel-title small { max-width: 50vw; }
  .head-actions .small-button { font-size: 0; width: 38px; height: 38px; }
  .head-actions .small-button::after { content: "👥"; font-size: 1rem; }
  .messages { padding-inline: 11px; }
  .message { grid-template-columns: 36px minmax(0,1fr); gap: 8px; }
  .message-avatar { width: 32px; height: 32px; }
  .system-message { padding-left: 44px; }
  .composer-wrap { padding-inline: 9px; padding-bottom: max(9px, env(safe-area-inset-bottom)); }
  .composer { grid-template-columns: 36px minmax(0,1fr) auto; }
  .send-button { padding-inline: 12px; }
  .typing-hint { padding-left: 43px; }
}

/* v2 member-role grouping */
.member-category {
  padding: 13px 8px 6px;
  color: #8290ad;
  font-size: .66rem;
  font-weight: 900;
  letter-spacing: .11em;
  text-transform: uppercase;
}

.member-category:first-child {
  padding-top: 5px;
}

.member-role-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
  flex: 0 0 22px;
  image-rendering: auto;
}

.member-mini-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 999px;
  border: 1px solid rgba(148,168,255,.22);
  color: #94a8ff;
  font-size: .56rem;
  font-weight: 800;
  vertical-align: middle;
}


/* v14: channel-status-only member list */
.channel-status-badge {
  display: inline-grid;
  place-items: center;
  min-width: 19px;
  height: 19px;
  margin-left: 7px;
  padding: 0 5px;
  border-radius: 999px;
  border: 1px solid rgba(148,168,255,.28);
  background: rgba(110,140,255,.10);
  color: var(--accent-2);
  font-size: .68rem;
  font-weight: 900;
  line-height: 1;
  vertical-align: middle;
}

.member-role-icon,
.member-mini-badge {
  display: none !important;
}


/* v15 Morphie identity */
.brand-mark {
  overflow: hidden;
  background: transparent !important;
  box-shadow: none !important;
}
.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* v15 member role colors */
.member-moderators .member-name { color: #f2a7d3; }
.member-voiced .member-name { color: #f2d675; }
.member-members .member-name { color: #a8e6b0; }
.member-moderators .avatar { border-color: rgba(242,167,211,.38); }
.member-voiced .avatar { border-color: rgba(242,214,117,.38); }
.member-members .avatar { border-color: rgba(168,230,176,.28); }

/* v15 room directory */
.room-browser {
  min-height: 0;
  overflow-y: auto;
  padding: 28px clamp(18px, 4vw, 52px) 42px;
}
.room-browser-intro {
  max-width: 900px;
  margin: 0 auto 22px;
}
.room-browser-intro h2 {
  margin: 5px 0 6px;
  font-size: clamp(1.6rem, 3vw, 2.25rem);
}
.room-browser-intro p {
  margin: 0 0 18px;
  color: var(--muted);
}
.room-search {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.025);
  border-radius: 14px;
  padding: 0 14px;
}
.room-search:focus-within {
  border-color: rgba(126,143,255,.75);
  box-shadow: 0 0 0 3px rgba(126,143,255,.10);
}
.room-search input {
  width: 100%;
  min-height: 48px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
}
.room-directory-status {
  max-width: 900px;
  margin: 0 auto 10px;
  color: var(--muted);
  font-size: .82rem;
}
.room-directory {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  gap: 10px;
}
.directory-room {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.022);
}
.directory-room:hover {
  background: rgba(255,255,255,.04);
}
.directory-room-info {
  min-width: 0;
}
.directory-room-info strong {
  font-size: 1rem;
}
.directory-room-info p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.directory-room-meta {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: .78rem;
}
.members-panel.directory-mode {
  visibility: hidden;
}
@media (max-width: 700px) {
  .room-browser { padding: 20px 12px 30px; }
  .directory-room { align-items: flex-start; }
  .directory-room-meta { flex-direction: column; align-items: flex-end; gap: 8px; }
}


/* v16 corrected Morphie logo */
.brand-mark {
  width: 40px;
  height: 40px;
  padding: 2px;
}
.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* v16 private-message navigation */
.pm-button .room-icon {
  font-size: .9rem;
}
.pm-button.active {
  background: rgba(102,130,237,.13);
  border-color: rgba(110,140,255,.24);
}


/* v17 critical logo containment fix
   The Morphie logo is now a background image instead of an <img>, so the native
   PNG dimensions can never overflow the navbar or intercept clicks. */
.brand {
  position: relative;
  z-index: 2;
  width: auto;
  max-width: max-content;
}

.brand-mark.brand-mark-morphie {
  flex: 0 0 40px;
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  max-width: 40px !important;
  min-height: 40px !important;
  max-height: 40px !important;
  padding: 0 !important;
  overflow: hidden !important;
  border-radius: 10px;
  background-color: transparent !important;
  background-image: url("./morphie-chat-icon.png") !important;
  background-repeat: no-repeat !important;
  background-position: center !important;
  background-size: contain !important;
  box-shadow: none !important;
  pointer-events: none;
}

.brand-mark.brand-mark-morphie img {
  display: none !important;
}


/* v18: never allow IRC content to widen the application */
.app-shell,
.chat-shell,
.chat-main,
.chat-column,
.messages,
.message,
.message > div,
.message-text,
.composer,
.composer-form,
.channel-header,
.channel-header > div {
  min-width: 0 !important;
}
.messages,
.message-text {
  max-width: 100%;
  overflow-x: hidden;
}
.message-text {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.composer,
.composer-form {
  width: 100%;
  max-width: 100%;
}
.composer-form {
  grid-template-columns: minmax(0, 1fr) auto !important;
}
#messageInput {
  min-width: 0;
  width: 100%;
  max-width: 100%;
}
#sendButton,
.send-button {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Joined rooms and PM close controls */
.joined-room-row,
.pm-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
}
.joined-room-row .room-button,
.pm-row .room-button {
  width: 100%;
  min-width: 0;
}
.sidebar-close {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 1.15rem;
  cursor: pointer;
}
.sidebar-close:hover,
.sidebar-close:focus-visible {
  color: var(--text);
  background: rgba(255,255,255,.07);
  outline: none;
}

/* Real emoji picker */
.emoji-wrap {
  position: relative;
  flex: 0 0 auto;
}
.emoji-picker {
  position: absolute;
  left: 0;
  bottom: calc(100% + 12px);
  width: min(330px, calc(100vw - 28px));
  max-height: 360px;
  overflow: hidden;
  z-index: 50;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #101a30;
  box-shadow: 0 18px 50px rgba(0,0,0,.38);
}
.emoji-picker-head {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.emoji-picker-head strong {
  display: block;
  margin-bottom: 8px;
}
.emoji-picker-head input {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0b1426;
  color: var(--text);
  font: inherit;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  max-height: 260px;
  overflow-y: auto;
  padding: 8px;
}
.emoji-choice {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 1.25rem;
  cursor: pointer;
}
.emoji-choice:hover,
.emoji-choice:focus-visible {
  background: rgba(255,255,255,.08);
  outline: none;
}


/* v19 definitive horizontal-overflow fix */
html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden !important;
}

body,
.morphie-app,
.topbar,
.chat-shell {
  max-width: 100vw !important;
}

.morphie-app {
  width: 100%;
  overflow-x: hidden !important;
}

.chat-shell {
  width: 100%;
  min-width: 0 !important;
  overflow: hidden !important;
  grid-template-columns: 270px minmax(0, 1fr) 240px !important;
}

.sidebar,
.conversation,
.members-panel {
  min-width: 0 !important;
}

.conversation {
  width: 100%;
  max-width: 100%;
  overflow: hidden !important;
}

.conversation-head,
.messages,
.composer-wrap,
.composer {
  width: 100%;
  max-width: 100%;
  min-width: 0 !important;
}

.conversation-head {
  overflow: hidden !important;
}

.channel-title,
.channel-title > div {
  min-width: 0 !important;
  max-width: 100%;
}

#channelName,
#channelTopic,
.channel-title strong,
.channel-title small {
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow: hidden !important;
  white-space: nowrap !important;
  text-overflow: ellipsis !important;
}

.messages {
  overflow-x: hidden !important;
}

.message,
.message > div,
.message-text {
  min-width: 0 !important;
  max-width: 100% !important;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
}

.composer {
  grid-template-columns: 40px minmax(0, 1fr) auto !important;
  overflow: visible;
}

#messageInput {
  width: 100%;
  min-width: 0 !important;
  max-width: 100%;
}

.send-button {
  min-width: max-content;
  flex: 0 0 auto;
  white-space: nowrap;
}

.emoji-wrap {
  position: relative;
  width: 40px;
  min-width: 40px;
  max-width: 40px;
}

.emoji-picker {
  display: block;
  z-index: 100;
}

.emoji-picker[hidden] {
  display: none !important;
}

@media (max-width: 1050px) {
  .chat-shell {
    grid-template-columns: 250px minmax(0, 1fr) !important;
  }
}

@media (max-width: 790px) {
  .chat-shell {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}


/* v21 desktop sidebar close cleanup */
@media (min-width: 791px) {
  #sidebarClose {
    display: none !important;
  }
}

/* v21 role avatars */
.role-avatar {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 800;
  font-size: .92rem;
}
.role-moderators {
  color: #f2a7d3;
  background: rgba(242,167,211,.12);
  border: 1px solid rgba(242,167,211,.28);
}
.role-voiced {
  color: #f2d675;
  background: rgba(242,214,117,.12);
  border: 1px solid rgba(242,214,117,.28);
}
.role-members {
  color: #a8e6b0;
  background: rgba(168,230,176,.10);
  border: 1px solid rgba(168,230,176,.22);
}

.sidebar-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.create-channel-button {
  margin-top: 12px;
}

/* v21 modal system */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 110;
  background: rgba(2,7,16,.72);
  backdrop-filter: blur(4px);
}
.morphie-modal {
  position: fixed;
  z-index: 120;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 32px));
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #111b31;
  color: var(--text);
  box-shadow: 0 28px 90px rgba(0,0,0,.48);
}
.morphie-modal[hidden],
.modal-backdrop[hidden] {
  display: none !important;
}
.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 18px 20px;
  background: #111b31;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 {
  margin: 5px 0 0;
  font-size: 1.25rem;
}
.modal-close {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: rgba(255,255,255,.05);
  color: var(--muted);
  cursor: pointer;
  font-size: 1.2rem;
}
.modal-close:hover {
  color: var(--text);
  background: rgba(255,255,255,.09);
}
.modal-body {
  padding: 18px 20px 22px;
}
.modal-actions,
.moderation-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}
.modal-section-title {
  margin: 20px 0 10px;
  color: var(--accent-2);
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .11em;
}
.modal-help {
  color: var(--muted);
  font-size: .82rem;
  line-height: 1.55;
}
.modal-form {
  display: grid;
  gap: 11px;
  margin: 10px 0;
}
.modal-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .78rem;
}
.modal-form input {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0b1426;
  color: var(--text);
}
.account-modal details {
  padding: 10px 0;
  border-top: 1px solid var(--line-soft);
}
.account-modal summary {
  cursor: pointer;
  font-weight: 750;
}
.danger-button {
  border-color: rgba(255,100,115,.35) !important;
  color: #ff9ba6 !important;
}
.whois-output {
  display: grid;
  gap: 7px;
}
.whois-line {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255,255,255,.035);
  font-size: .84rem;
  overflow-wrap: anywhere;
}
.whois-line.muted {
  color: var(--muted);
}
.channel-registration-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255,255,255,.025);
}
.channel-registration-box strong {
  font-size: .85rem;
}

@media (max-width: 620px) {
  .morphie-modal {
    width: calc(100vw - 18px);
    max-height: calc(100vh - 18px);
  }
  .channel-registration-box {
    align-items: stretch;
    flex-direction: column;
  }
}

body.members-collapsed .chat-shell { grid-template-columns:270px minmax(0,1fr)!important; }
body.members-collapsed .members-panel { display:none!important; }
.message-nick-moderators{color:#f2a7d3}.message-nick-voiced{color:#f2d675}.message-nick-members{color:#a8e6b0}
.role-away{color:#a9b4c8;background:rgba(169,180,200,.10);border:1px solid rgba(169,180,200,.22)}
.format-wrap{position:relative;width:40px;min-width:40px;max-width:40px}
.composer{grid-template-columns:40px 40px minmax(0,1fr) auto!important}
.format-picker{position:absolute;left:0;bottom:calc(100% + 12px);width:285px;z-index:100;border:1px solid var(--line);border-radius:14px;background:#101a30;box-shadow:0 18px 50px rgba(0,0,0,.38);padding:12px}
.format-picker[hidden]{display:none!important}
.format-picker-head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:10px}.format-toggles{display:flex;gap:7px;margin-bottom:12px}
.format-toggle{width:36px;height:34px;border:1px solid var(--line);border-radius:8px;background:rgba(255,255,255,.035);color:var(--text);cursor:pointer}
.format-toggle.active,#formatButton.active{background:rgba(110,140,255,.18);border-color:rgba(110,140,255,.42)}
.format-label{margin-bottom:7px;color:var(--muted);font-size:.75rem}.format-colors{display:grid;grid-template-columns:repeat(8,1fr);gap:6px}
.format-color{width:26px;height:26px;border-radius:7px;border:2px solid rgba(255,255,255,.12);cursor:pointer}.format-color.selected{outline:2px solid var(--accent-2);outline-offset:2px}
.channel-admin-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
@media(max-width:620px){.channel-admin-grid{grid-template-columns:1fr}.composer{grid-template-columns:36px 36px minmax(0,1fr) auto!important}}

/* v23 */
.connection-pill{font:inherit;cursor:pointer}
.nick-status-button{width:100%;border:0;background:transparent;color:inherit;text-align:left;cursor:pointer}
.section-toggle{width:100%;display:flex;justify-content:space-between;align-items:center;border:0;background:transparent;color:inherit;cursor:pointer;padding:0}
.member-category-toggle{width:100%;display:flex;justify-content:space-between;align-items:center;border:0;background:transparent;color:inherit;cursor:pointer}
.member-name .channel-status-badge{display:none!important}
.moderator-name-owner{color:#ffc2e5!important}.moderator-name-admin{color:#f5add8!important}.moderator-name-op{color:#e997c9!important}.moderator-name-halfop{color:#d984b9!important}
.directory-user-count{color:#79e58b;font-weight:800}
.channel-mode-badge{display:inline-block;margin:6px 6px 0 0;padding:3px 7px;border:1px solid var(--line);border-radius:999px;color:var(--muted);font-size:.68rem}
.user-profile-summary{display:grid;gap:6px;padding:12px;margin-bottom:14px;border:1px solid var(--line);border-radius:10px;background:rgba(255,255,255,.025);font-size:.84rem}
.user-profile-summary a,.inline-channel-link{color:var(--accent-2)}
.inline-channel-link{border:0;background:transparent;padding:0 2px;cursor:pointer;text-decoration:underline;font:inherit}
.service-response-output{display:grid;gap:7px;max-height:52vh;overflow:auto}
.service-response-line{padding:8px 10px;border-radius:8px;background:rgba(255,255,255,.035);font-size:.84rem;white-space:pre-wrap;overflow-wrap:anywhere}
.channel-mode-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;margin:10px 0 14px}
.channel-mode-grid label{padding:10px;border:1px solid var(--line);border-radius:9px;background:rgba(255,255,255,.025);font-size:.8rem}
#memosSection .room-button{position:relative}
#disconnectButton{display:none!important}
@media(max-width:620px){.channel-mode-grid{grid-template-columns:1fr}}


/* v24 connection button theme */
.connection-pill {
  appearance: none;
  border: 1px solid var(--line) !important;
  background: rgba(255,255,255,.035) !important;
  color: var(--text) !important;
  border-radius: 999px;
  padding: 8px 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: none !important;
}
.connection-pill:hover,
.connection-pill:focus-visible {
  background: rgba(255,255,255,.065) !important;
  border-color: rgba(120,145,230,.45) !important;
  outline: none;
}
.connection-pill[data-state="online"] #connectionText {
  color: #8ce7a0;
}

/* v24 Channel Controls cleanup */
.channel-control-section {
  border-top: 1px solid var(--line-soft);
  padding: 0;
}
.channel-control-section:first-of-type {
  border-top: 0;
}
.channel-control-section > summary {
  cursor: pointer;
  list-style: none;
  padding: 15px 0;
  color: var(--accent-2);
  font-size: .76rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: .11em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.channel-control-section > summary::-webkit-details-marker {
  display: none;
}
.channel-control-section > summary::after {
  content: "▾";
  color: var(--muted);
  font-size: .82rem;
}
.channel-control-section:not([open]) > summary::after {
  content: "▸";
}
.channel-control-section-body {
  padding: 0 0 18px;
}

/* v24 BotServ */
.bot-list-row {
  display: grid;
  grid-template-columns: minmax(90px, .7fr) minmax(140px, 1.5fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 14px !important;
}
.bot-list-row strong {
  color: var(--accent-2);
}
.bot-list-row span {
  color: var(--muted);
  overflow-wrap: anywhere;
}
.bot-settings-current {
  padding: 13px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.028);
  font-weight: 750;
}
.bot-toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 12px;
}
.bot-toggle-grid label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.025);
}
.bot-toggle-grid input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

/* more room in service response rows */
.service-response-output {
  gap: 10px !important;
}
.service-response-line {
  padding: 11px 13px !important;
  line-height: 1.45;
}

@media (max-width: 620px) {
  .bot-list-row,
  .bot-toggle-grid {
    grid-template-columns: 1fr;
  }
  .bot-list-row .small-button {
    width: 100%;
  }
}


/* v25 Channel Management refinements */
#channelRegistrationBox {
  gap: 16px;
}

.bot-list-row {
  cursor: default;
}

.bot-list-row .small-button {
  justify-self: end;
}

.channel-control-section-body > .modal-actions:first-child {
  margin-bottom: 12px;
}


/* v26 Connection / server notices */
.connection-summary {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255,255,255,.025);
}

.connection-server-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 10px;
}

.connection-server-row select {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0b1426;
  color: var(--text);
}

.server-notice-list {
  display: grid;
  gap: 9px;
  max-height: 320px;
  overflow-y: auto;
}

.server-notice-row {
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: rgba(255,255,255,.025);
}

.server-notice-row.important {
  border-color: rgba(255,142,150,.24);
}

.server-notice-meta {
  color: var(--muted);
  font-size: .68rem;
  margin-bottom: 4px;
}

.server-notice-body {
  font-size: .82rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

/* v26 service result visibility */
.service-response-modal {
  z-index: 140;
}

.service-response-output {
  min-height: 58px;
}

/* v27 IRC-style Server Notices window */
.server-notice-list{
  height:300px!important;min-height:300px;max-height:300px!important;
  overflow-y:auto!important;overflow-x:hidden;display:block!important;
  padding:10px 12px;border:1px solid var(--line);border-radius:10px;
  background:#08101e;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono",monospace;
  font-size:.78rem;line-height:1.5
}
.server-notice-line{display:flex;align-items:flex-start;gap:7px;padding:2px 0}
.server-notice-line.important .server-notice-text{color:#ffadb5}
.server-notice-time{flex:0 0 auto;color:#75839d}
.server-notice-source{flex:0 0 auto;color:#9fb4ff;font-weight:700}
.server-notice-text{min-width:0;color:#c9d3e6;overflow-wrap:anywhere}
.server-notice-empty{color:var(--muted)}
@media(max-width:620px){.server-notice-list{height:240px!important;min-height:240px;max-height:240px!important}}


/* v28 channel mode badges in active channel header */
.channel-mode-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 5px;
}

.channel-mode-badges:empty {
  display: none;
}

.channel-mode-badges .channel-mode-badge {
  margin: 0;
}

/* v28 away is neutral regardless of IRC role */
.role-avatar.role-away {
  color: #aab3c3 !important;
  background: rgba(170,179,195,.08) !important;
  border-color: rgba(170,179,195,.25) !important;
}

/* keep the username privilege color while away */
.member-moderators .member-name,
.member-voiced .member-name,
.member-members .member-name {
  opacity: 1;
}

/* v29 bottom-left Memos button */
.sidebar-footer-actions {
  display:flex;
  align-items:center;
  gap:8px;
}
#memosFooterButton {
  display:inline-flex;
  align-items:center;
  gap:7px;
}
#memosFooterButton[hidden] { display:none!important; }
.footer-badge {
  min-width:18px;
  height:18px;
  padding:0 5px;
  display:inline-grid;
  place-items:center;
  border-radius:999px;
  background:var(--accent);
  color:#fff;
  font-size:.66rem;
  font-weight:800;
}

/* v29 modal stacking */
.service-response-modal { z-index:260!important; }
.response-modal-open .modal-backdrop { z-index:230!important; }
.toast { z-index:320!important; }
.morphie-modal:not(.service-response-modal) { z-index:120; }

/* away role styling remains for bottom-left self status only */
.role-away {
  color:#aab3c3!important;
  background:rgba(170,179,195,.08)!important;
  border-color:rgba(170,179,195,.25)!important;
}

/* v30 footer controls remain clickable above sidebar layout */
.sidebar-footer-actions {
  position: relative;
  z-index: 3;
}
#accountButton,
#memosFooterButton {
  cursor: pointer;
}

/* v31 final ChanServ response overlay */
.response-modal-open .service-response-modal,
.service-response-modal:not([hidden]){
  display:block!important;
  z-index:300!important;
}
.response-modal-open .modal-backdrop{z-index:250!important}
