:root {
  /* IRCCloud-inspired palette: dark navy chat area, slightly darker navy sidebar */
  --bg-primary: #1a2a40;
  --bg-secondary: #16273c;
  --bg-tertiary: #1f3550;
  --bg-input: #0f1f33;
  --bg-hover: #233f5e;
  --bg-active: #2a4868;
  --text-primary: #d8e2ec;
  --text-secondary: #8aa0b8;
  --text-muted: #5c7290;
  --accent: #5b9bd5;
  --accent-hover: #4a8bc5;
  --border: #1f3550;
  --success: #4caf50;
  --warning: #ff9800;
  --error: #f44336;
  --join: #6cb87a;
  --quit: #d57b7b;
  --mode: #6fa8dc;
  --op-color: #f5c542;
  --voice-color: #6cb87a;
  --nick-colors: #e06c75, #d19a66, #e5c07b, #98c379, #56b6c2, #61afef, #c678dd;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --radius: 6px;
  --sidebar-width: 220px;
  --userlist-width: 180px;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 15px;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* Screens */
.screen {
  display: none;
  height: 100%;
}
.screen.active {
  display: flex;
}

/* Connect Screen */
#connect-screen,
#login-screen {
  justify-content: center;
  align-items: center;
  background: var(--bg-primary);
  position: fixed;
  inset: 0;
  z-index: 100;
}

.connect-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 440px;
  max-width: 95vw;
  box-shadow: var(--shadow);
}

.connect-header {
  text-align: center;
  margin-bottom: 32px;
}

.connect-header h1 {
  font-size: 29px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.version {
  font-size: 13px;
  color: var(--text-muted);
}

.connect-credit {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.connect-credit a {
  color: var(--accent);
  text-decoration: none;
}

.connect-credit a:hover {
  text-decoration: underline;
}

.connect-credit-sep {
  margin: 0 6px;
  opacity: 0.6;
}

.connect-user-label {
  color: var(--text-secondary);
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  margin-left: 6px;
  font-size: inherit;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
}
.btn-link:hover {
  text-decoration: underline;
}

.form-row {
  display: flex;
  gap: 12px;
}

.flex-1 { flex: 1; }
.flex-2 { flex: 2; }

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group input[type="email"] {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-sans);
  transition: border-color 0.15s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding-top: 22px;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-size: 15px !important;
  color: var(--text-primary) !important;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.btn-connect {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 8px;
}

.btn-connect:hover {
  background: var(--accent-hover);
}

.btn-connect:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Client Layout */
.client-layout {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
}

/* Sidebar — IRCCloud-style navy palette */
.sidebar {
  --sb-bg: #1f3a57;
  --sb-bg-hover: #274b6e;
  --sb-header-bg: #183048;
  --sb-text: #9fb3c8;
  --sb-text-active: #ffffff;
  --sb-border: #14283c;

  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--sb-text);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
}

.network-block {
  display: flex;
  flex-direction: column;
}

.network-header {
  padding: 12px 14px;
  background: var(--sb-header-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--sb-border);
}

.network-header:hover {
  background: #1d3854;
}

.network-name {
  font-weight: 700;
  font-size: 15px;
  /* Muted at rest like a channel row — the header background, weight and shield
     already mark it as a network. It only brightens to white when its Server
     buffer is the active one or has unread, so it stops competing with the
     genuinely-active channel for attention (see .active / .has-unread below). */
  color: var(--sb-text);
  letter-spacing: 0.2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.network-header.active .network-name,
.network-header.has-unread .network-name {
  color: var(--sb-text-active);
}

.network-shield {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  flex-shrink: 0;
}

.network-shield.network-shield-secure {
  color: #5cb85c;
}

.network-shield.network-shield-insecure {
  color: #e06c75;
}

.network-shield.network-shield-off {
  color: var(--text-muted);
  opacity: 0.5;
}

.network-header.has-unread .network-name::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 8px;
  border-radius: 50%;
  background: #4a9eff;
  vertical-align: middle;
}

/* Fold/unfold twisty. The glyph points right when collapsed and rotates down
   when the channels are showing — the usual disclosure convention. */
.network-twisty {
  flex-shrink: 0;
  padding: 3px;
  margin-left: -4px;
  margin-right: 2px;
  color: var(--sb-text);
  opacity: 0.65;
}
.network-twisty:hover {
  opacity: 1;
}
.network-twisty svg {
  transition: transform 0.15s ease;
  transform: rotate(90deg);
}
.network-block.collapsed .network-twisty svg {
  transform: rotate(0deg);
}

/* A folded network rolls its channels' unread state onto the header: plain talk
   keeps the blue .has-unread dot, a real ping turns the name orange and adds
   the count badge (and drops the dot, so it's one signal, not two). */
.network-header.has-mention .network-name {
  color: #ff8a65;
}
.network-header.has-mention .network-name::after {
  display: none;
}
.network-header .unread-badge {
  margin-left: 6px;
  flex-shrink: 0;
  background: #ff7043;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.network-gear {
  color: var(--sb-text);
  opacity: 0.7;
}

.network-gear:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--sb-text-active);
  opacity: 1;
}

.channel-list {
  display: flex;
  flex-direction: column;
  padding: 4px 0 8px;
}

.channel-item {
  padding: 2.9px 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--sb-text);
  transition: background 0.1s, color 0.1s;
  user-select: none;
  position: relative;
}

.channel-item:hover {
  background: var(--sb-bg-hover);
  color: var(--sb-text-active);
}

.channel-item.active {
  color: var(--sb-text-active);
  font-weight: 700;
  background: #2a4f76;
  box-shadow: inset 3px 0 0 #5b9bd5;
}

/* Generic activity (someone wrote in the channel but didn't mention me) —
   just bold-white the channel name, no badge. */
.channel-item.has-activity:not(.active) {
  color: var(--sb-text-active);
  font-weight: 600;
}

/* Nick highlight — a distinct "you were pinged" notice beside the channel. */
/* Someone said your name here: the row itself goes red, not just the badge. */
.channel-item.has-mention:not(.active) {
  color: #ff7043;
  font-weight: 700;
  box-shadow: inset 3px 0 0 #ff7043;
}

.channel-item.has-mention:not(.active):hover {
  color: #ff8a65;
}

/* A mention in the channel you're already looking at still flags the row —
   it clears when you answer or switch back into it. */
.channel-item.has-mention.active {
  color: #ff8a65;
  box-shadow: inset 3px 0 0 #ff7043;
}

/* Muted: the row stays quiet whatever is said in it. Dimmed rather than hidden,
   with the bell as the reason — a channel that never lights up looks broken
   otherwise. A mention still overrides all of this (below by specificity). */
.channel-item.muted:not(.active):not(.has-mention) {
  color: var(--sb-text);
  font-weight: 400;
  opacity: 0.62;
}

.channel-item .mute-mark {
  margin-left: auto;
  font-size: 10px;
  opacity: 0.75;
  flex: 0 0 auto;
}

/* The ✕ and the mention badge both want the right-hand end of the row. */
.channel-item:hover .mute-mark,
.channel-item.has-mention .mute-mark {
  display: none;
}

.channel-item .unread-badge {
  margin-left: auto;
  background: #ff7043;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.channel-item .close-btn {
  margin-left: auto;
  opacity: 0;
  /* Sized as a tap target rather than a glyph: the row is dense, so the ✕ has
     to be easy to hit with a thumb without pushing the channel name around. */
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 20px;
  margin-right: -4px;
  padding: 0;
  border-radius: 4px;
  background: none;
  border: none;
  color: var(--sb-text);
  cursor: pointer;
  font-size: 19px;
  line-height: 1;
}

.channel-item .close-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.channel-item:hover .close-btn {
  opacity: 1;
}

.channel-item:hover .unread-badge {
  display: none;
}

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--sb-border);
  background: var(--sb-header-bg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar .btn-small {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--sb-text-active);
}

.sidebar .btn-small:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-disconnect-full {
  color: #f6a5a5 !important;
}

.btn-small {
  width: 100%;
  padding: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-small:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

.chat-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
  min-height: 44px;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.chat-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-title {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  color: #fff;
}

.chat-topic-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  flex: 1;
  line-height: 1.25;
}

.chat-topic-meta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-topic-meta.hidden { display: none; }

.chat-topic {
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-user-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  background: rgba(91, 155, 213, 0.18);
  color: #9bc1ea;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 600;
}
.chat-user-badge.hidden { display: none; }

.chat-body-wrapper {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.chat-messages-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  position: relative;   /* anchors the jump-to-bottom pill */
}

/* Jump-to-bottom pill — shown only while scrolled up off the live tail. */
.scroll-bottom-pill {
  position: absolute;
  bottom: 16px;
  right: 20px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.scroll-bottom-pill:hover {
  background: var(--bg-hover);
}
.scroll-bottom-pill.hidden { display: none; }
.scroll-bottom-pill .pill-arrow {
  font-size: 15px;
}
.scroll-bottom-pill .pill-count {
  background: #ff7043;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
}
.scroll-bottom-pill .pill-count.hidden { display: none; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
}

/* Network settings popover — anchored to the cog button in network headers */
.network-menu {
  position: fixed;
  z-index: 300;
  width: 240px;
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  padding: 12px 14px;
  font-size: 14px;
}
.network-menu.hidden { display: none; }

.network-menu-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.network-menu-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  color: var(--text-secondary);
  font-size: 13px;
}
.network-menu-row .label { color: var(--text-muted); }
.network-menu-row .value {
  color: var(--text-primary);
  font-weight: 600;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.network-menu-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.network-menu-status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.network-menu-status.connected { color: var(--join); background: rgba(108, 184, 122, 0.15); }
.network-menu-status.connecting { color: var(--mode); background: rgba(111, 168, 220, 0.15); }
.network-menu-status.disconnected { color: var(--quit); background: rgba(213, 123, 123, 0.18); }

.network-menu-separator {
  height: 1px;
  background: var(--border);
  margin: 10px -14px 8px;
}

.network-menu-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.network-menu-actions button {
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.network-menu-actions button:hover:not(:disabled) {
  background: var(--bg-hover);
}
.network-menu-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.network-menu-actions .btn-primary { color: #9bc1ea; }
.network-menu-actions .btn-secondary { color: var(--text-primary); }
.network-menu-actions .btn-danger { color: #f6a5a5; }

/* Per-network IRC operator credentials, inline in the network menu */
.network-menu-oper-toggle {
  width: 100%;
  text-align: left;
  padding: 4px 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  cursor: pointer;
}
.network-menu-oper-toggle:hover { color: var(--text-primary); }

.network-menu-oper-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 0 2px;
}
.network-menu-oper-body.hidden { display: none; }
.network-menu-oper-body input {
  width: 100%;
  padding: 6px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
}
.network-menu-oper-body input:focus {
  outline: none;
  border-color: var(--accent);
}
.network-menu-oper-save {
  padding: 6px 10px;
  border: none;
  border-radius: 4px;
  background: var(--bg-hover);
  color: #9bc1ea;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.network-menu-oper-save:hover:not(:disabled) { background: var(--border); }
.network-menu-oper-save:disabled { opacity: 0.45; cursor: not-allowed; }
.network-menu-oper-status {
  font-size: 12px;
  color: var(--text-muted);
  min-height: 14px;
}

/* Whois modal — styled after a classic desktop client's whois window:
   solid blue title bar, flat panel, prose lines and square bullets. Colours are
   sampled from that window rather than the app palette, on purpose. */
.modal-content.whois-content {
  width: 600px;
  padding: 0;
  overflow: hidden;
  border: 1px solid #0b1a28;
  border-radius: 0;
  background: #17334f;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.whois-titlebar {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 10px;
  background: #2e669e;
  border-bottom: 1px solid #11263b;
}
.whois-titlebar-label {
  color: #88b3dd;
  font-size: 15px;
}
.whois-titlebar-nick {
  flex: 1;
  color: #ebf2f9;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.whois-close {
  border: none;
  background: transparent;
  color: #b8d2ea;
  font-size: 20px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}
.whois-close:hover { color: #ffffff; }

.whois-body {
  padding: 10px 14px 14px;
  max-height: 65vh;
  overflow-y: auto;
  background: #17334f;
}
.whois-line {
  color: #c4d9ee;
  font-size: 14px;
  line-height: 22px;
  word-break: break-word;
}

.whois-channels {
  list-style: none;
  margin: 0;
  padding: 0 0 2px;
}
.whois-channels li {
  display: flex;
  align-items: center;
  gap: 9px;
  line-height: 20px;
}
.whois-channels li::before {
  content: '';
  flex: 0 0 auto;
  width: 4px;
  height: 4px;
  background: #c4d9ee;
}
.whois-channel {
  border: none;
  background: transparent;
  padding: 0;
  color: #c4d9ee;
  font-size: 14px;
  line-height: 20px;
  cursor: pointer;
}
.whois-channel:hover:not(:disabled) { text-decoration: underline; }
.whois-channel:disabled { cursor: default; }

/* "Load earlier messages" — history beyond the visible 48-hour window */
.load-earlier {
  display: flex;
  justify-content: center;
  padding: 10px 0 6px;
}
.load-earlier button {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 13px;
  padding: 5px 14px;
  cursor: pointer;
}
.load-earlier button:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* Day separator between messages from different calendar days */
.day-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 10px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.day-separator::before,
.day-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.day-separator span { white-space: nowrap; }
/* Same shape as a day separator, in the highlight colour so it reads as a
   position rather than a date. */
.unread-marker { color: var(--error); }
.unread-marker::before,
.unread-marker::after { background: var(--error); opacity: 0.55; }

/* Context menu (right-click: nick, sidebar row, chat area) */
.context-menu {
  position: fixed;
  z-index: 320;
  min-width: 180px;
  max-width: 260px;
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  padding: 6px;
  font-size: 14px;
}
.context-menu.hidden { display: none; }

.context-menu-title {
  padding: 4px 8px 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 8px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}
.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item.danger { color: #f6a5a5; }
.context-menu-item.hidden { display: none; }

/* Emoji shortcode type-ahead popup — the ":smi" list above the composer. */
.emoji-ac {
  position: fixed;
  z-index: 320;
  min-width: 180px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  padding: 4px;
}
.emoji-ac.hidden { display: none; }
.emoji-ac-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  color: var(--text-primary);
}
.emoji-ac-item.active,
.emoji-ac-item:hover { background: var(--bg-hover); }
.emoji-ac-glyph {
  font-size: 18px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}
.emoji-ac-name {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Command popup rows: usage on the left, one-line help on the right. */
.cmd-ac-item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
}
.cmd-ac-item.active,
.cmd-ac-item:hover { background: var(--bg-hover); }
.cmd-ac-name {
  font-family: monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}
.cmd-ac-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Hover a nick anywhere (chat line, join/quit line, user list) → user@host */
.nick-tooltip {
  position: fixed;
  z-index: 340;
  max-width: 320px;
  padding: 5px 9px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none; /* never swallow the click meant for the nick */
}
.nick-tooltip.hidden { display: none; }
.nick-tooltip.unknown { color: var(--text-muted); }

.context-menu-separator {
  height: 1px;
  background: var(--border);
  margin: 6px -6px;
}

.context-menu-section-toggle {
  width: 100%;
  text-align: left;
  padding: 6px 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  cursor: pointer;
}
.context-menu-section-toggle:hover { color: var(--text-primary); }
.context-menu-section.hidden { display: none; }

.context-menu-inline {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 8px 6px;
}
.context-menu-inline.hidden { display: none; }
.context-menu-inline input {
  width: 100%;
  padding: 5px 7px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
}
.context-menu-inline input:focus { outline: none; border-color: var(--accent); }
.context-menu-inline-go {
  padding: 5px 8px;
  border: none;
  border-radius: 4px;
  background: var(--bg-hover);
  color: #f6a5a5;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.context-menu-inline-go:hover { background: var(--border); }

/* Cog button next to network name in sidebar */
.network-cog {
  margin-left: 6px;
  color: var(--sb-text);
  opacity: 0.6;
}
.network-cog:hover,
.network-cog.active {
  opacity: 1;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.msg {
  padding: 1px 16px;
  display: flex;
  gap: 8px;
  line-height: 1.5;
  font-size: 14px;
}

.msg-meta {
  /* Timestamp (36px of 12px mono) + the 6px gap + the nick column + the 10px
     padding before the rule and its 1px border = 53px of fixed furniture.
     The nick column itself is measured from the nicks the buffer actually
     contains (--nick-measured, set by noteNickWidth in app.js) and clamped
     here: never below the 95px the old fixed column gave, never past a third
     of the window, so one 25-character nick can't crowd out the text. Nicks
     longer than that still ellipsise — the hover tooltip has the full one. */
  --nick-min: 95px;
  --nick-max: min(200px, 33vw);
  flex: 0 0 calc(54px + clamp(var(--nick-min), var(--nick-measured, 95px), var(--nick-max)));
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
  /* Rule between the nick column and the message text. Rows sit 1px apart, so
     the borders stack into one continuous line down the buffer. */
  padding-right: 10px;
  border-right: 1px solid rgba(255, 255, 255, 0.07);
}

.msg:hover {
  background: rgba(255,255,255,0.025);
}

.msg-time {
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font-mono);
  white-space: nowrap;
  flex: 0 0 auto;
  padding-top: 2px;
}

.msg-nick {
  font-weight: 700;
  white-space: nowrap;
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
  padding-top: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-nick-ref {
  cursor: context-menu;
  text-decoration-color: transparent;
}
.msg-nick-ref:hover {
  text-decoration: underline;
  text-decoration-color: currentColor;
}
/* The nick column is a right-click target too — hint at it on hover. */
.msg-nick[data-nick] { cursor: context-menu; }

.msg-nick .nick-prefix {
  color: var(--op-color);
  font-weight: 700;
}
.msg-nick .nick-prefix.voice { color: var(--voice-color); }

.msg-text {
  flex: 1;
  word-break: break-word;
  min-width: 0;
  color: var(--text-primary);
}

/* Inline image preview under the line that linked it. */
.msg-image {
  display: block;
  margin: 6px 0 2px;
  max-width: 420px;
}
.msg-image img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* Multi-line paste confirmation, directly above the composer. */
.paste-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 13px;
}
.paste-bar.hidden { display: none; }
.paste-bar span { flex: 1; min-width: 0; }

/* Keyboard focus. The sidebar rows and user list entries are focusable (they
   are divs with handlers, made reachable in the accessibility pass), and
   without a ring tabbing through them is invisible. :focus-visible so a mouse
   click doesn't leave an outline behind. */
.channel-item:focus-visible,
.network-header:focus-visible,
.user-item:focus-visible,
.btn-icon:focus-visible,
.btn-small:focus-visible,
.btn-composer:focus-visible,
.close-btn:focus-visible,
.context-menu-item:focus-visible,
.alias-del:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Buffer search: a strip between the header and the message list. */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}
.search-bar.hidden { display: none; }
.search-bar input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-sans);
}
.search-bar input:focus { outline: none; border-color: var(--accent); }
.search-count {
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
}
mark.search-hit {
  background: var(--accent);
  color: #0f1f33;
  border-radius: 2px;
  padding: 0 1px;
}

/* Scope toggle: this buffer, or the backlog the server keeps on disk. Reads as
   a segmented control rather than a button, so it looks like state and not
   like an action. */
.search-scope {
  flex: 0 0 auto;
  padding: 5px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font-sans);
  white-space: nowrap;
  cursor: pointer;
}
.search-scope:hover { color: var(--text-primary); border-color: var(--accent); }
.search-scope.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f1f33;
  font-weight: 600;
}
.search-scope:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* A result from the history search. The chip says which network and channel
   it came from, since the list crosses all of them. */
.search-where {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  white-space: nowrap;
}
.msg-search-result { cursor: pointer; border-radius: var(--radius); }
.msg-search-result:hover { background: var(--bg-hover); }
.msg-search-result:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
/* A hit in a buffer this tab doesn't have open: still readable, but it goes
   nowhere, so it must not look clickable. */
.msg-search-result.search-result-cold { cursor: default; opacity: 0.75; }
.msg-search-result.search-result-cold:hover { background: none; }
.search-note {
  color: var(--text-secondary);
  font-size: 13px;
  font-style: italic;
}

/* Landing on a line jumped to from the search: a fade rather than a lasting
   mark, so the buffer looks normal a moment later. */
.msg-jump-flash { animation: jump-flash 2s ease-out; border-radius: var(--radius); }
@keyframes jump-flash {
  0%, 40% { background: rgba(97, 175, 239, 0.28); }
  100% { background: transparent; }
}

/* IRC formatting codes (see formatIrcHtml). The colours themselves are inline
   styles straight from the mIRC palette; only the attributes are classes. */
.irc-b { font-weight: 700; }
.irc-i { font-style: italic; }
.irc-u { text-decoration: underline; }
.irc-s { text-decoration: line-through; }
.irc-u.irc-s { text-decoration: underline line-through; }
.irc-mono { font-family: var(--font-mono); }
/* Reverse video with no colours of its own: the buffer's own two swap over. */
.irc-reverse {
  color: var(--bg-primary);
  background-color: var(--text-primary);
}

.msg-text a,
.chat-topic a {
  color: var(--accent);
  text-decoration: none;
}

.msg-text a:hover,
.chat-topic a:hover {
  text-decoration: underline;
}

.msg.msg-action {
  color: var(--text-secondary);
  font-style: italic;
}

.msg.msg-action .msg-nick {
  color: var(--text-secondary);
}

.msg.msg-system .msg-nick,
.msg.msg-join .msg-nick,
.msg.msg-quit .msg-nick,
.msg.msg-mode .msg-nick,
.msg.msg-nick-change .msg-nick {
  font-weight: 700;
  font-size: 14px;
}

.msg.msg-system .msg-text {
  color: var(--text-secondary);
}

.msg.msg-join {
  color: var(--join);
}
.msg.msg-join .msg-nick { color: var(--join); }
.msg.msg-join .msg-text { color: var(--join); }

.msg.msg-quit {
  color: var(--quit);
}
.msg.msg-quit .msg-nick { color: var(--quit); }
.msg.msg-quit .msg-text { color: var(--quit); }

.msg.msg-mode {
  color: var(--mode);
}
.msg.msg-mode .msg-nick { color: var(--mode); }
.msg.msg-mode .msg-text { color: var(--mode); }

.msg.msg-nick-change {
  color: var(--text-secondary);
}
.msg.msg-nick-change .msg-nick { color: var(--text-secondary); }

.msg.msg-error {
  color: var(--error);
}
.msg.msg-error .msg-nick { color: var(--error); }
.msg.msg-error .msg-text { color: var(--error); }

.msg.msg-notice {
  color: #b8d17d;
}
.msg.msg-notice .msg-nick { color: #b8d17d; }
.msg.msg-notice .msg-text { color: #b8d17d; }

.msg.msg-motd {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
}

.msg.msg-motd .msg-nick {
  display: none;
}

/* User list panel */
.user-list-panel {
  width: var(--userlist-width);
  min-width: var(--userlist-width);
  border-left: 1px solid var(--border);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-list-panel.hidden {
  display: none;
}

.user-list-header {
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.user-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.user-item {
  padding: 3px 14px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.user-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.user-nick {
  font-weight: 500;
  color: #ffffff;
}

.user-nick.ircop {
  color: #61afef;
}

.user-nick.away {
  opacity: 0.5;
}

/* User-list sections */
.userlist-section {
  display: flex;
  flex-direction: column;
}

.userlist-section-header {
  padding: 5px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.userlist-section-count {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.85;
}

.userlist-section-ops {
  background: rgba(94, 61, 135, 0.18);
}
.userlist-section-ops .userlist-section-header {
  background: rgba(94, 61, 135, 0.55);
  color: #d6bcf7;
  border-top: 1px solid rgba(94, 61, 135, 0.9);
  border-bottom: 1px solid rgba(94, 61, 135, 0.9);
}

.userlist-section-voiced {
  background: rgba(40, 99, 45, 0.15);
}
.userlist-section-voiced .userlist-section-header {
  background: rgba(40, 99, 45, 0.55);
  color: #a5d6a7;
  border-top: 1px solid rgba(40, 99, 45, 0.9);
  border-bottom: 1px solid rgba(40, 99, 45, 0.9);
}

.userlist-section-members {
  background: rgba(38, 73, 112, 0.2);
}
.userlist-section-members .userlist-section-header {
  background: rgba(38, 73, 112, 0.6);
  color: #9bc1ea;
  border-top: 1px solid rgba(38, 73, 112, 0.9);
  border-bottom: 1px solid rgba(38, 73, 112, 0.9);
}

.user-item .user-mode {
  color: var(--op-color);
  font-weight: 700;
  min-width: 10px;
  display: inline-block;
}

.user-item .user-mode.voice {
  color: var(--voice-color);
}

/* Open-proxy (DNSBL) verdict badge, pushed to the right of the nick. */
.user-proxy-badge {
  margin-left: auto;
  font-size: 12px;
  line-height: 1;
  flex: 0 0 auto;
}
.user-proxy-badge.proxy-listed {
  color: #e06c75;
  font-weight: 700;
}
.user-proxy-badge.proxy-clean {
  color: #98c379;
  opacity: 0.7;
}
.user-proxy-badge.proxy-pending {
  color: #abb2bf;
  opacity: 0.6;
}
.user-proxy-badge.proxy-error {
  color: #e5c07b;
}

/* Chat Input */
.chat-input-area {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

#message-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-time {
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font-mono);
  min-width: 38px;
}

.input-nick-prefix {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  color: var(--text-primary);
}
.input-nick-prefix:empty {
  display: none;
}
.input-nick-prefix .nick-prefix {
  color: var(--op-color);
  margin-right: 2px;
}

#message-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-sans);
}

#message-input:focus {
  outline: none;
  border-color: var(--accent);
}

#message-input::placeholder {
  color: var(--text-muted);
}

#message-input:disabled {
  opacity: 0.5;
}

.btn-send {
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-send:hover {
  background: var(--accent-hover);
}

.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Toggle sidebar button (mobile) */
.btn-toggle-sidebar {
  display: none;
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 8px;
  cursor: pointer;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 360px;
  max-width: 90vw;
  box-shadow: var(--shadow);
}

.modal-content h3 {
  margin-bottom: 20px;
  font-size: 19px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* Upload modal: the picked image above the line that goes with it. The preview
   is capped rather than scaled to fill, so a portrait photo and a wide
   screenshot both keep their shape and the dialog keeps its height. */
.upload-preview {
  margin-bottom: 18px;
  padding: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.upload-preview img {
  max-width: 100%;
  max-height: 220px;
  border-radius: var(--radius);
  display: block;
  margin: 0 auto;
}

.upload-file {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  min-width: 0;
}

.upload-filename {
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-filesize {
  color: var(--text-muted);
  flex: 0 0 auto;
}

/* Settings modal */
.settings-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}
.settings-inline input[type="number"] {
  width: 90px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-sans);
}
.settings-inline input:focus { outline: none; border-color: var(--accent); }
.settings-unit { color: var(--text-secondary); font-size: 14px; }
/* The notification-sound snooze: a dropdown sitting under its checkbox, so it
   is indented to read as belonging to it rather than as a sibling setting. */
.silence-inline {
  margin: 2px 0 2px 23px;
  flex-wrap: wrap;
  font-size: 14px;
}
.silence-inline label {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 400;
  margin: 0;
}
.silence-inline select {
  padding: 5px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-sans);
  cursor: pointer;
}
.silence-inline select:focus { outline: none; border-color: var(--accent); }
.silence-inline select:disabled { opacity: 0.5; cursor: not-allowed; }
#notify-silence-state { color: var(--accent); }
.settings-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  font-weight: 400;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
}
.settings-check input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}
/* The alias editor needs more room than a one-field dialog does, and the whole
   card scrolls once a long alias list outgrows the viewport. */
#settings-modal .modal-content {
  width: 560px;
  max-height: 88vh;
  overflow-y: auto;
}

/* Muted channels: read-only rows, one unmute button each */
.mute-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mute-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.mute-target {
  font-size: 14px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mute-network,
.mute-empty {
  font-size: 12px;
  color: var(--text-muted);
}

/* Alias editor: one row per user-defined /command */
.alias-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.alias-row {
  display: grid;
  grid-template-columns: auto 130px 1fr auto;
  align-items: start;
  gap: 6px;
}
.alias-slash {
  color: var(--text-muted);
  font-family: var(--font-mono, monospace);
  line-height: 38px;
}
.alias-row input.alias-name,
.alias-row textarea.alias-text {
  padding: 9px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-sans);
  min-width: 0;
}
.alias-row textarea.alias-text {
  resize: vertical;
  line-height: 1.4;
}
.alias-row input.alias-name:focus,
.alias-row textarea.alias-text:focus { outline: none; border-color: var(--accent); }
.alias-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 8px 4px;
}
.alias-del:hover { color: var(--error); }
.btn-small.alias-add { margin-top: 8px; }

@media (max-width: 600px) {
  .alias-row {
    grid-template-columns: auto 1fr auto;
  }
  .alias-row textarea.alias-text {
    grid-column: 1 / -1;
  }
}

.form-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}
.form-hint code {
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 11px;
}

.btn-cancel {
  padding: 10px 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
}

.btn-cancel:hover {
  background: var(--bg-hover);
}

/* Nick colors — 16-slot palette, distinct on dark backgrounds */
.nick-0  { color: #e06c75; }  /* salmon red   */
.nick-1  { color: #ff7b54; }  /* coral orange */
.nick-2  { color: #d19a66; }  /* amber        */
.nick-3  { color: #e5c07b; }  /* yellow       */
.nick-4  { color: #b8d17d; }  /* lime         */
.nick-5  { color: #98c379; }  /* green        */
.nick-6  { color: #4ec9b0; }  /* teal         */
.nick-7  { color: #56b6c2; }  /* cyan         */
.nick-8  { color: #61afef; }  /* sky blue     */
.nick-9  { color: #7aa2f7; }  /* periwinkle   */
.nick-10 { color: #bd93f9; }  /* lavender     */
.nick-11 { color: #c678dd; }  /* purple       */
.nick-12 { color: #ff79c6; }  /* pink         */
.nick-13 { color: #f78fb3; }  /* rose         */
.nick-14 { color: #d8a657; }  /* gold         */
.nick-15 { color: #89b4fa; }  /* ice blue     */

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--bg-active);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .btn-toggle-sidebar {
    display: flex;
  }

  .user-list-panel {
    display: none !important;
  }

  .msg-nick {
    min-width: 60px;
  }
}

/* Only a genuinely narrow screen gives the nick column back — at 480px and
   under, a 95px floor would eat half the message text. The measured width still
   applies, it just gets a lower floor and is allowed a bigger share of a small
   screen, since there is nowhere else for a long nick to go. */
@media (max-width: 480px) {
  .msg-meta {
    --nick-min: 79px;
    --nick-max: 45vw;
  }
}

.connect-error {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(244, 67, 54, 0.12);
  border: 1px solid var(--error);
  border-radius: var(--radius);
  color: var(--error);
  font-size: 14px;
  word-break: break-word;
}
.connect-error.hidden { display: none; }

#connect-screen.as-modal {
  background: rgba(0, 0, 0, 0.55);
}

.connect-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.connect-actions .btn-connect { flex: 1; }
.connect-actions .btn-cancel {
  padding: 12px 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
}
.connect-actions .btn-cancel.hidden { display: none; }
.connect-actions .btn-cancel:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Saved networks picker on connect screen */
.saved-networks {
  margin-bottom: 16px;
  padding: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.saved-networks.hidden { display: none; }
.saved-networks-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 4px 8px 8px;
}
.saved-network-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.saved-network-row:hover {
  background: var(--bg-hover);
}
.saved-network-host {
  font-weight: 600;
  font-size: 14px;
}
.saved-network-meta {
  font-size: 12px;
  color: var(--text-muted);
}

/* ZNC bouncer helper on connect screen */
.znc-toggle-group {
  margin-top: -4px;
}
.znc-panel {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.znc-panel.hidden { display: none; }
.znc-panel-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.znc-panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.btn-znc-apply {
  padding: 7px 12px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn-znc-apply:hover { background: var(--accent-hover); }
.znc-hint {
  font-size: 12px;
  color: var(--text-muted);
}
.znc-hint code {
  font-size: 11.5px;
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 4px;
  border-radius: 3px;
}

/* Add-network button at sidebar bottom */
.btn-add-network {
  display: block;
  width: calc(100% - 20px);
  margin: 8px 10px 12px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  color: #c9d6e5;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn-add-network:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.network-close {
  color: var(--sb-text);
  opacity: 0.55;
  margin-left: 6px;
}
.network-close:hover {
  background: rgba(255, 255, 255, 0.1);
  opacity: 1;
  color: #fff;
}

/* --- DCC --- */
/* A DCC chat is a direct socket, not a channel or a query, so its sidebar row
   is tinted to say so at a glance. */
.channel-item.dcc-item {
  font-style: italic;
}

/* Accept/Decline on a DCC offer line, and the download link a finished
   transfer turns into. */
.msg-text a.dcc-action {
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: 0 6px;
  margin: 0 1px;
  font-size: 12px;
}

.msg-text a.dcc-action:hover {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

/* Once you've answered an offer the buttons stay put but stop inviting a
   second click. */
.msg.dcc-handled .msg-text a.dcc-action {
  opacity: 0.45;
  pointer-events: none;
}

/* The user@host on join/part/quit lines — present but subordinate to the nick. */
.msg-userhost {
  opacity: 0.75;
  font-size: 12px;
}

/* --- Highlights --- */
/* A message that mentions you by name, or any private message. Tinted with a
   marker down the left edge so it stands out when scrolling back, without
   drowning the surrounding conversation. */
.msg.msg-highlight {
  background: rgba(255, 112, 67, 0.11);
  box-shadow: inset 3px 0 0 #ff7043;
}

.msg.msg-highlight .msg-text {
  color: #ffd9cc;
}

.msg.msg-highlight .msg-time {
  color: #ff8a65;
}

/* --- Composer buttons (emoji, image upload) --- */
.btn-composer {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  padding: 0;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-composer:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-composer.active {
  background: var(--bg-active);
  color: var(--text-primary);
}

.btn-composer:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Upload in flight: pulse rather than spin, so it needs no extra markup. */
.btn-composer.busy {
  animation: composer-busy 1s ease-in-out infinite;
}

@keyframes composer-busy {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* --- Emoji picker --- */
.emoji-picker {
  position: fixed;
  z-index: 400;
  width: 330px;
  max-height: 320px;
  overflow-y: auto;
  padding: 10px 12px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.emoji-picker.hidden {
  display: none;
}

.emoji-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin: 10px 0 4px;
}

.emoji-group-title:first-child {
  margin-top: 0;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}

.emoji-btn {
  background: none;
  border: none;
  border-radius: 5px;
  padding: 3px 0;
  font-size: 20px;
  line-height: 1.2;
  cursor: pointer;
}

.emoji-btn:hover {
  background: var(--bg-hover);
}

/* "The server has moved on without you" banner. Top-centre, not bottom: the
   composer lives at the bottom and a banner over it would block typing until
   dismissed. Above every modal, so a tab sitting on a dialog still sees it. */
.update-banner {
  position: fixed;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 24px);
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text-primary);
  font-size: 13px;
}

.update-banner.hidden { display: none; }

.update-banner .btn-small {
  width: auto;
  flex: none;
  padding: 5px 12px;
  color: var(--text-primary);
  border-color: var(--accent);
}

.update-banner-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
}

.update-banner-close:hover { color: var(--text-primary); }

/* Login ↔ register switch under the auth forms, and the account block at the
   foot of Settings. */
.auth-switch {
  margin-top: 14px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}
.auth-switch.hidden { display: none; }
.auth-switch .btn-link { font-size: 13px; padding: 0; }
/* This stylesheet declares .hidden per component rather than globally, so both
   halves of the front page need their own rule — without the first one the two
   forms rendered stacked on top of each other, and without the second the
   invite and reason fields showed on instances that ask for neither. */
#register-form.hidden { display: none; }
#login-form.hidden { display: none; }
.form-group.hidden { display: none; }

/* --- The front page: sign in / create account --- */
/* The registration form is the tallest thing in the app that is not a chat
   log, so the card scrolls rather than running off a phone screen. */
.auth-card {
  max-height: 92vh;
  overflow-y: auto;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.auth-tab {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.auth-tab:hover { color: var(--text-primary); }
.auth-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}
.auth-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
/* With registration closed there is only one door, and a lone tab reading
   "Sign in" is just a label — so the whole strip goes. */
.auth-tab.hidden { display: none; }
.auth-tabs.single { display: none; }

.auth-intro {
  margin: -6px 0 18px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.auth-intro.hidden { display: none; }

#register-form textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-sans);
  line-height: 1.45;
  resize: vertical;
  transition: border-color 0.15s;
}
#register-form textarea:focus { outline: none; border-color: var(--accent); }
#register-form textarea::placeholder { color: var(--text-muted); }
#register-reason-group.hidden { display: none; }

/* Turnstile in interaction-only mode draws nothing unless it wants a click,
   so the holder must take no room until it does. */
/* Two fields on one line, and one per line as soon as that stops fitting —
   a first and last name side by side is the shape everyone expects, right up
   until the screen is 380px wide. */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-row .form-group { min-width: 0; }
@media (max-width: 460px) { .form-row { grid-template-columns: 1fr; } }

.turnstile:empty { display: none; }
.turnstile { margin: 0 0 14px; }

.auth-done { text-align: center; }
.auth-done.hidden { display: none; }
.auth-done-mark {
  width: 48px;
  height: 48px;
  margin: 4px auto 16px;
  border-radius: 50%;
  background: rgba(76, 175, 80, 0.14);
  border: 1px solid var(--success);
  color: var(--success);
  font-size: 24px;
  line-height: 46px;
}
.auth-done h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}
.auth-done p {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-secondary);
  margin-bottom: 18px;
}

.account-section {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.account-section.hidden { display: none; }
.account-title {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.account-email {
  margin-left: 6px;
  font-weight: 400;
  color: var(--text-secondary);
}
.account-inline { align-items: flex-start; gap: 10px; }
.account-inline .form-group { flex: 1; min-width: 0; margin-bottom: 8px; }
.account-actions { justify-content: flex-start; align-items: center; gap: 10px; margin-top: 4px; }
.account-status { font-size: 12px; color: var(--text-secondary); }
.account-status.ok { color: var(--success, #98c379); }
.account-status.err { color: var(--danger, #e06c75); }
.btn-danger {
  background: transparent;
  border: 1px solid var(--danger, #e06c75);
  color: var(--danger, #e06c75);
}
.btn-danger:hover { background: var(--danger, #e06c75); color: #fff; }
#delete-account-form { margin-top: 18px; }
