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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3248;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --text: #e2e4f0;
  --bubble-mine: #0a84ff;
  --bubble-mine-text: #ffffff;
  --bubble-theirs: #3a3a3c;
  --bubble-theirs-text: #f0f0f0;
  --text-muted: #8b92b8;
  --danger: #ed4245;
  --success: #3ba55c;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

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

button, .btn {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
  transition: background .15s;
}
button:hover, .btn:hover { background: var(--accent-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #c03537; }

input, textarea, select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  padding: 9px 12px;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

/* ---- Auth pages ---- */
.auth-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 40px;
  width: 100%;
  max-width: 380px;
}
.auth-card h1 { font-size: 22px; margin-bottom: 24px; text-align: center; }
.field { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.auth-card .btn-submit { width: 100%; margin-top: 8px; padding: 11px; font-size: 15px; }
.auth-card .footer-link { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-muted); }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 6px; min-height: 18px; }

/* ---- App shell ---- */
.app-shell {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  width: 280px;
  min-width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-header h2 { font-size: 16px; flex: 1; }
.sidebar-header .icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 18px;
}
.sidebar-header .icon-btn:hover { background: var(--surface2); color: var(--text); }
.search-box { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.search-box input { font-size: 13px; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.conv-item:hover, .conv-item.active { background: var(--surface2); }
.conv-avatar-wrap { position: relative; flex-shrink: 0; }
.conv-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
  color: #fff;
}
.conv-status-dot {
  position: absolute; bottom: 1px; right: 1px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface2);
  border: 2px solid var(--surface);
}
.conv-status-dot.online { background: #22c55e; }
.conv-info { flex: 1; min-width: 0; }
.conv-name-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.conv-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.conv-badge { display: none; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #0a84ff; color: #fff; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.conv-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-other-status { font-size: 11px; color: var(--text-muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-style: italic; }
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.profile-area { flex: 1; cursor: pointer; min-width: 0; }
.profile-area .username { font-size: 13px; font-weight: 600; }
.my-status { font-size: 11px; color: var(--text-muted); margin-top: 2px; font-style: italic; }
.my-status.hidden { display: none; }

/* ---- Status modal ---- */
.status-emoji-presets { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; max-height: 220px; overflow-y: auto; padding-right: 2px; }
.status-emoji-section { display: flex; flex-direction: column; gap: 5px; }
.status-emoji-section-title { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.status-emoji-section-row { display: flex; flex-wrap: wrap; gap: 6px; }
.status-emoji-preset-btn { font-size: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px; cursor: pointer; line-height: 1; transition: border-color 0.15s; }
.status-emoji-preset-btn:hover { border-color: var(--accent, #0a84ff); }
.status-emoji-preset-btn.active { border-color: var(--accent, #0a84ff); background: rgba(10,132,255,0.12); }
.status-input-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.status-emoji-input { width: 52px; font-size: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; color: var(--text-primary); text-align: center; }
.status-text-input { width: 100%; font-size: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; color: var(--text-primary); box-sizing: border-box; }
.status-counter { position: absolute; right: 8px; bottom: -18px; font-size: 10px; color: var(--text-muted); }
.status-btn-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.btn-primary { background: var(--accent, #0a84ff); color: #fff; border: none; border-radius: 8px; padding: 6px 16px; cursor: pointer; font-size: 13px; }

/* ---- Search results dropdown ---- */
.search-results {
  position: absolute;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 240px;
  box-shadow: 0 4px 20px #00000066;
  max-height: 240px;
  overflow-y: auto;
}
.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
}
.search-result-item:hover { background: var(--surface2); }
.search-wrap { position: relative; }

/* ---- Chat area ---- */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-header {
  padding: 10px 20px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.chat-mobile-back-btn {
  display: none;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  font-size: 18px;
  line-height: 1;
}
.chat-mobile-back-btn:hover { background: var(--border); }
.chat-header-summary {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.chat-header-summary:hover {
  background: var(--surface2);
  border-color: var(--border);
}
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-header-btn {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
}
.chat-header-btn:hover { background: var(--border); }
#chatHeader { font-weight: 700; font-size: 16px; }
.chat-status { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.chat-status.online { color: #22c55e; }
.chat-search-panel {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-search-panel input {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  padding: 7px 10px;
}
.chat-search-count {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 42px;
  text-align: center;
}
.chat-search-nav {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  width: 28px;
  height: 28px;
  border-radius: 7px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
}
.chat-search-nav:hover { background: var(--border); }
.chat-pin-banner {
  margin-top: 8px;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.chat-pin-banner:hover { background: var(--border); }
.chat-pin-label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  flex-shrink: 0;
}
.chat-pin-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg {
  max-width: 68%;
  padding: 9px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg-theirs {
  align-self: flex-start;
  background: var(--bubble-theirs);
  color: var(--bubble-theirs-text);
  border-bottom-left-radius: 4px;
}
.msg-mine {
  align-self: flex-end;
  background: var(--bubble-mine);
  color: var(--bubble-mine-text);
  border-bottom-right-radius: 4px;
}
.msg-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.msg-group { display: flex; flex-direction: column; width: 100%; }
.msg-group.mine { align-items: flex-end; }
.msg-group.theirs { align-items: flex-start; }
.msg-time { font-size: 10px; color: var(--text-muted); margin-top: 3px; }
.msg-tick { color: rgba(255,255,255,0.6); font-size: 11px; }
.msg-tick.read { color: #ffffff; }
.msg-link {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
}
.msg-link:hover {
  opacity: .82;
}

.typing-indicator {
  padding: 2px 20px 4px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  min-height: 20px;
}
.typing-indicator.hidden { display: none; }
.upload-status {
  padding: 9px 20px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.upload-status-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 12px;
  color: var(--text-muted);
}
.upload-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  flex-shrink: 0;
  animation: upload-spin 0.8s linear infinite;
}
.upload-status-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.upload-status-percent {
  flex-shrink: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.upload-progress-track {
  height: 4px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface2);
}
.upload-progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.15s ease;
}
@keyframes upload-spin {
  to { transform: rotate(360deg); }
}
.chat-input-bar {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--surface);
}
.emoji-wrap { position: relative; flex-shrink: 0; }
.emoji-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  line-height: 1;
  opacity: .75;
  transition: opacity .15s, background .15s;
  flex-shrink: 0;
}
.emoji-btn:hover { opacity: 1; background: var(--surface2); }
.emoji-picker {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  width: min(92vw, 360px);
  box-shadow: 0 6px 24px #00000077;
  z-index: 200;
}
.emoji-picker-tabs {
  display: flex;
  gap: 0;
  margin-top: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  border-top: 1px solid var(--border);
  padding-top: 6px;
  cursor: grab;
  user-select: none;
}
.emoji-picker-tabs::-webkit-scrollbar { display: none; }
.emoji-tab {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  opacity: .6;
  flex-shrink: 0;
  transition: opacity .1s, background .1s;
}
.emoji-tab + .emoji-tab {
  border-left: 1px solid var(--border);
  border-radius: 0;
}
.emoji-tab:first-child { border-radius: 6px 0 0 6px; }
.emoji-tab:last-child { border-radius: 0 6px 6px 0; }
.emoji-tab:hover, .emoji-tab.active { opacity: 1; background: var(--surface2); }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  height: 180px;
  overflow-y: auto;
  overflow-x: hidden;
}
.emoji-grid button {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  line-height: 1;
  transition: background .1s;
}
.emoji-grid button:hover { background: var(--surface2); }

/* ---- Picker top tabs (Emoji / Stickers) ---- */
.picker-top-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.picker-top-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 4px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: 0;
  transition: color .15s, border-color .15s;
}
.picker-top-tab.active { color: var(--text); border-bottom-color: var(--accent, #0a84ff); }
.picker-top-tab:hover { color: var(--text); }

/* ---- Sticker picker ---- */
.sticker-content { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.sticker-content.hidden { display: none; }
.emoji-content.hidden { display: none; }
.sticker-pack-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  padding: 2px 2px 8px;
  border-bottom: 1px solid var(--border);
}
.sticker-pack-btn {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 4px;
  cursor: pointer;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color .15s, transform .12s;
}
.sticker-pack-btn img { width: 100%; height: 100%; object-fit: contain; border-radius: 8px; }
.sticker-pack-btn.active { border-color: var(--accent, #0a84ff); transform: translateY(-1px); }
.sticker-toolbar {
  display: flex;
  justify-content: flex-end;
  margin: 2px 0 6px;
}
.sticker-animation-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.sticker-animation-toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 5px;
  width: 100%;
  max-height: min(52vh, 420px);
  overflow-y: auto;
  padding-top: 2px;
  align-content: start;
}
.sticker-grid-btn {
  background: var(--surface2);
  border: none;
  border-radius: 10px;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  transition: background .1s;
}
.sticker-grid-btn img,
.sticker-grid-btn video,
.sticker-grid-btn div,
.sticker-grid-btn svg,
.sticker-pack-btn video,
.sticker-pack-btn div,
.sticker-pack-btn svg {
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  object-position: center;
}
.sticker-grid-btn:hover { background: var(--surface); }
.sticker-empty { font-size: 12px; color: var(--text-muted); text-align: center; padding: 20px 0; margin: 0; }

.sticker-hint-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  scrollbar-width: thin;
}
.sticker-hint-bar.hidden { display: none; }
.sticker-hint-btn {
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  padding: 3px;
  cursor: pointer;
  overflow: hidden;
}
.sticker-hint-btn:hover { border-color: var(--accent); }
.sticker-hint-btn img,
.sticker-hint-btn video,
.sticker-hint-btn div,
.sticker-hint-btn svg {
  display: block;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}

/* ---- Sticker message ---- */
.msg-sticker {
  width: 140px;
  height: 140px;
  object-fit: contain;
  display: block;
}
.msg-sticker video,
video.msg-sticker {
  width: 140px;
  height: 140px;
  object-fit: contain;
  display: block;
}
.msg-sticker svg {
  width: 100%;
  height: 100%;
  display: block;
}
.chat-input-bar textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.4;
  border-radius: 12px;
}
.chat-input-bar button { flex-shrink: 0; border-radius: 12px; padding: 0 18px; height: 40px; }

@media (max-width: 820px) {
  .app-shell {
    width: 100%;
  }
  .sidebar {
    display: none;
  }
  .chat-area {
    width: 100%;
    min-width: 0;
  }
  .chat-header {
    padding: calc(10px + env(safe-area-inset-top)) 12px 8px;
  }
  .chat-mobile-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .chat-header-main {
    gap: 8px;
  }
  .chat-header-summary {
    padding: 6px 4px;
  }
  .chat-messages {
    padding: 12px;
  }
  .typing-indicator {
    padding: 2px 12px 4px;
  }
  .chat-input-bar {
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }
  .sticker-hint-bar {
    padding: 8px 12px;
  }
  .upload-status {
    padding: 8px 12px 9px;
  }
  .chat-input-bar textarea {
    min-height: 38px;
  }
  .msg {
    max-width: min(84%, 28rem);
  }
  .msg-file-card {
    max-width: min(84vw, 320px);
  }
  .msg-image-wrap,
  .msg-image-group-wrap {
    max-width: min(78vw, 320px);
  }
  .msg-image {
    max-width: min(78vw, 320px);
  }
  .msg-image-slot {
    width: min(37vw, 150px);
    height: min(37vw, 150px);
  }
  .msg-copy-btn {
    opacity: 1;
    pointer-events: auto;
  }
  .chat-search-panel {
    flex-wrap: wrap;
  }
  .chat-search-count {
    min-width: 0;
    order: 2;
  }
}

/* ---- Empty state ---- */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 12px;
}
.empty-state .big-icon { font-size: 56px; }
.empty-state p { font-size: 15px; }

/* ---- Admin page ---- */
.admin-wrap { flex: 1; overflow-y: auto; padding: 32px; max-width: 1080px; margin: 0 auto; width: 100%; }
.admin-wrap h1 { font-size: 26px; margin-bottom: 6px; }
.admin-page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.admin-page-head p {
  color: var(--text-muted);
  font-size: 14px;
}
.admin-tab-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.admin-tab-btn {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 9px 14px;
  border-radius: 999px;
}
.admin-tab-btn:hover {
  background: var(--surface2);
  color: var(--text);
}
.admin-tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.admin-panel { display: none; }
.admin-panel.active { display: block; }
.section {
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
}
.section h2 { font-size: 16px; margin-bottom: 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-size: 12px; }
.admin-bot-searchable-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  color: var(--text-muted);
  font-size: 13px;
}
.admin-inline-checkbox {
  width: 16px !important;
  min-width: 16px !important;
  max-width: 16px !important;
  height: 16px !important;
  padding: 0 !important;
  margin: 0 !important;
  flex: 0 0 16px;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge-used { background: var(--surface2); color: var(--text-muted); }
.badge-active { background: #1e3a27; color: var(--success); }
.badge-expired { background: #3a3320; color: #f5c26b; }
.badge-admin { background: #2a1e3a; color: #b794f4; }
.badge-banned { background: rgba(237, 66, 69, 0.18); color: #ff9da0; }
.admin-update-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.admin-update-lane {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface2) 58%, transparent);
  padding: 14px;
}
.admin-update-lane-head,
.admin-update-version-row,
.admin-update-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}
.admin-update-lane-head {
  justify-content: space-between;
  margin-bottom: 12px;
}
.admin-update-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.admin-update-badge-stable {
  background: rgba(126, 200, 163, 0.16);
  color: var(--success);
}
.admin-update-badge-beta {
  background: rgba(245, 194, 107, 0.16);
  color: #f5c26b;
}
.admin-update-state {
  color: var(--text-muted);
  font-size: 12px;
}
.admin-update-version-row {
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}
.admin-update-version {
  color: var(--text);
  font-size: 22px;
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.admin-update-code {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 4px;
}
.admin-update-download {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}
.admin-update-download:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.admin-update-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 14px;
}
.admin-update-meta-item {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.admin-update-meta-item span,
.admin-update-notes span {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.admin-update-meta-item strong,
.admin-update-meta-item code {
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}
.admin-update-sha code {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-update-notes {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.admin-update-notes p,
.admin-update-empty-copy {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.admin-update-notes-empty p {
  font-style: italic;
}
.admin-update-empty,
.admin-update-error {
  min-height: 188px;
}
.admin-update-error {
  border-color: rgba(237, 66, 69, 0.32);
}
.admin-ban-reason-preview {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.35;
  max-width: 220px;
  word-break: break-word;
}
.admin-ban-modal {
  position: fixed;
  inset: 0;
  z-index: 1300;
}
.admin-ban-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
}
.admin-ban-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(420px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}
.admin-ban-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.admin-ban-head h3 {
  font-size: 18px;
  margin-bottom: 4px;
}
.admin-ban-head p {
  color: var(--text-muted);
  font-size: 13px;
}
.admin-ban-mode-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.admin-ban-mode-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
}
.admin-ban-mode-option input {
  width: auto;
}
.admin-ban-actions {
  display: flex;
  justify-content: flex-end;
}
.invite-url { font-size: 12px; color: var(--text-muted); word-break: break-all; margin-top: 10px; background: var(--surface2); padding: 10px 14px; border-radius: var(--radius); }
.copy-btn { margin-top: 8px; font-size: 12px; padding: 5px 12px; }
.invite-qr { margin-top: 10px; width: fit-content; padding: 10px; background: #fff; border-radius: 10px; border: 1px solid var(--border); }
.invite-qr img { display: block; width: 176px; height: 176px; image-rendering: pixelated; }
.nav-bar {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  gap: 16px;
  align-items: center;
}
.nav-bar a { font-size: 14px; color: var(--text-muted); }
.nav-bar a:hover, .nav-bar a.active { color: var(--text); }

@media (max-width: 720px) {
  .admin-wrap {
    padding: 20px 14px 28px;
  }
  .section {
    padding: 14px;
  }
  .admin-tab-bar {
    width: 100%;
  }
  .admin-tab-btn {
    flex: 1 1 calc(50% - 8px);
    justify-content: center;
  }
  .admin-update-grid,
  .admin-update-meta {
    grid-template-columns: 1fr;
  }
  .admin-update-version-row {
    flex-direction: column;
  }
  .admin-update-download {
    width: 100%;
  }
}

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

/* ---- Reactions ---- */

/* Hover reaction button — appears beside each bubble on desktop hover */

/* msg-row wraps the bubble + react button as a flex row so the button
   sits directly next to the bubble regardless of bubble width */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  width: 100%;
  max-width: 100%;
}
.msg-group.mine .msg-row {
  justify-content: flex-end;
}
.msg-group.theirs .msg-row {
  justify-content: flex-start;
}
.msg-react-btn,
.msg-copy-btn {
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s, background .1s;
}
.msg-group:hover .msg-react-btn,
.msg-group:focus-within .msg-react-btn,
.msg-group:hover .msg-copy-btn,
.msg-group:focus-within .msg-copy-btn {
  opacity: 1;
  pointer-events: auto;
}
.msg-react-btn:hover,
.msg-copy-btn:hover { background: var(--border); }

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background .1s, border-color .1s;
  line-height: 1.6;
}

.reaction-chip:hover {
  background: rgba(255, 255, 255, 0.14);
}

.reaction-chip.active {
  background: rgba(88, 101, 242, 0.25);
  border-color: rgba(88, 101, 242, 0.7);
}

.reaction-bar {
  position: fixed;
  z-index: 300;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 6px 10px;
  display: flex;
  gap: 2px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

.reaction-bar button {
  background: none;
  border: none;
  font-size: 22px;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
  transition: background .1s, transform .1s;
}

.reaction-bar button:hover {
  background: var(--surface2);
  transform: scale(1.2);
}

/* ---- Image messages ---- */
.msg-image-wrap {
  position: relative;
  max-width: 280px;
  min-width: 80px;
  min-height: 60px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface2);
  cursor: pointer;
}
.msg-image-group-wrap {
  max-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.msg-image-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}
.msg-image-slot {
  position: relative;
  width: 138px;
  height: 138px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface2);
  cursor: pointer;
}
.msg-image {
  display: block;
  max-width: 280px;
  max-height: 400px;
  width: auto;
  height: auto;
  border-radius: var(--radius);
  cursor: zoom-in;
}
.msg-image-slot .msg-image {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: cover;
  border-radius: 0;
}
.msg-image-dl-btn {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .2s;
  cursor: pointer;
  text-decoration: none;
}
.msg-image-wrap:hover .msg-image-dl-btn { opacity: 1; }
.msg-image-spinner {
  width: 80px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 22px;
}
.msg-image-slot .msg-image-spinner {
  width: 100%;
  height: 100%;
}
.msg-image-spinner::after { content: '...'; }
.msg-image-slot-more {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}
.msg-image-group-actions {
  display: flex;
  justify-content: flex-end;
}
.msg-image-group-dl-btn {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.msg-image-group-dl-btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.msg-image-expired {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 13px;
  border: 1px solid var(--border);
}
.msg-image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.82);
}
.msg-image-lightbox-img {
  max-width: min(92vw, 1280px);
  max-height: 88vh;
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}
.msg-image-lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  cursor: pointer;
  font-size: 12px;
}
.msg-image-lightbox-close:hover {
  background: rgba(0, 0, 0, 0.62);
}
.msg-image-lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
}
.msg-image-lightbox-nav.prev { left: 14px; }
.msg-image-lightbox-nav.next { right: 14px; }
.msg-image-lightbox-count {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.42);
  color: #fff;
  font-size: 12px;
}
body.modal-open {
  overflow: hidden;
}
.msg-file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface2);
  border: 1px solid var(--border);
  min-width: 200px;
  max-width: 280px;
}
.msg-file-icon { font-size: 24px; flex-shrink: 0; }
.msg-file-info { flex: 1; min-width: 0; }
.msg-file-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.msg-file-size { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.msg-file-dl-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--accent);
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.msg-file-dl-btn:hover { opacity: 1; }
.msg-file-dl-btn:disabled { opacity: 0.3; cursor: default; }
.msg-voice-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "icon info"
    "controls controls";
  align-items: center;
  row-gap: 8px;
}
.msg-voice-card .msg-file-icon { grid-area: icon; }
.msg-voice-card .msg-file-info { grid-area: info; }
.msg-voice-controls {
  grid-area: controls;
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-voice-load-btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  min-width: 58px;
}
.msg-voice-audio {
  width: 190px;
  max-width: 100%;
  height: 30px;
}
#chatMessages.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}
.img-btn,
.attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  width: 40px;
  height: 40px;
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
}
.img-btn:hover,
.attach-btn:hover { background: var(--surface2); color: var(--text); }
.img-btn.is-disabled,
.attach-btn.is-disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* ---- Settings panel ---- */
.settings-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 399;
}
.settings-overlay.open { display: block; }
.settings-panel {
  position: fixed;
  top: 0; left: 0;
  width: 260px; height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 400;
  display: flex; flex-direction: column;
  transform: translateX(-100%);
  transition: transform .22s ease;
}
.settings-panel.open { transform: translateX(0); }
.settings-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 15px;
}
.settings-close-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 16px; cursor: pointer; padding: 4px 6px;
  border-radius: 6px;
}
.settings-close-btn:hover { background: var(--surface2); color: var(--text); }
.settings-section { padding: 16px; }
.settings-section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted); margin-bottom: 12px;
}
.settings-swatches {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 8px;
}
.settings-swatch-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}
.settings-swatch {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 2px solid var(--border);
  background-color: var(--bg);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color .15s, transform .1s;
}
.settings-swatch:hover { border-color: var(--text-muted); transform: scale(1.05); }
.settings-swatch.active { border-color: var(--accent); }
.swatch-none-label { font-size: 11px; color: var(--text-muted); }
.settings-swatch-label { font-size: 11px; color: var(--text-muted); text-align: center; }

/* ---- Theme cards ---- */
.settings-theme-cards { display: flex; gap: 8px; flex-wrap: wrap; }
.settings-theme-card {
  width: 72px; text-align: center; cursor: pointer;
  border-radius: 8px; padding: 4px;
  border: 2px solid var(--border);
  transition: border-color .15s;
}
.settings-theme-card:hover { border-color: var(--text-muted); }
.settings-theme-card.active { border-color: var(--accent); }
.theme-swatch {
  height: 36px;
  border-radius: 5px 5px 0 0;
  margin-bottom: 4px;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
}
.theme-accent-strip { width: 100%; height: 4px; }

.theme-swatch-night { background: #0f1221; }
.theme-accent-night { background: #6ea8fe; }

.theme-swatch-sage { background: #0d1f15; }
.theme-accent-sage { background: #4caf7d; }

.theme-swatch-ember { background: #130c05; }
.theme-accent-ember { background: #f47b2c; }

.theme-swatch-midnight { background: #0e0b1a; }
.theme-accent-midnight { background: #8b5cf6; }

.theme-swatch-rose { background: #1a0d14; }
.theme-accent-rose { background: #f472b6; }
.theme-label { font-size: 11px; color: var(--text-muted); }

/* ---- Settings toggle row ---- */
.settings-toggle-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; color: var(--text-primary); font-size: 14px; cursor: pointer;
}

.settings-action-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}

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

.settings-display-name-reset {
  margin-right: auto;
  color: var(--accent);
}

.settings-display-name-reset[hidden] {
  display: none;
}

.settings-modal-panel {
  left: 50%;
  top: 50%;
  width: min(360px, calc(100vw - 24px));
  height: auto;
  max-height: calc(100vh - 40px);
  transform: translate(-50%, -50%);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}

.settings-modal-copy {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 12px;
}

.settings-text-input {
  width: 100%;
  box-sizing: border-box;
}

.settings-input-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 8px;
  margin-bottom: 12px;
}

/* ---- Settings version ---- */
.settings-version {
  font-size: 11px; color: var(--text-muted); text-align: center;
  padding: 12px 16px 4px;
}

.sidebar-settings-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 16px; cursor: pointer; padding: 5px 7px;
  border-radius: 6px; line-height: 1;
}
.sidebar-settings-btn:hover { background: var(--surface2); color: var(--text); }

/* ---- Reply bar (above input) ---- */
.reply-bar {
  display: flex;
  align-items: center;
  padding: 6px 14px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  gap: 10px;
}
.reply-bar.hidden { display: none; }
.reply-bar-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-left: 3px solid var(--accent);
  padding-left: 8px;
}
.reply-bar-sender { font-size: 11px; font-weight: 600; color: var(--accent); }
.reply-bar-text {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-bar-cancel {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
  border-radius: 4px;
}
.reply-bar-cancel:hover { color: var(--text); background: var(--border); }

/* ---- Reply quote inside bubble ---- */
.msg-reply-quote {
  background: rgba(0,0,0,0.2);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 5px 8px;
  margin-bottom: 6px;
  cursor: pointer;
}
.msg-reply-quote:hover { background: rgba(0,0,0,0.32); }
.reply-quote-sender {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}
.reply-quote-content {
  display: block;
  font-size: 12px;
  color: rgba(255,255,255,0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

/* ---- Reply button (mirrors react button) ---- */
.msg-reply-btn {
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s, background .1s;
}
.msg-group:hover .msg-reply-btn,
.msg-group:focus-within .msg-reply-btn {
  opacity: 1;
  pointer-events: auto;
}
.msg-reply-btn:hover { background: var(--border); }
.msg-pin-btn {
  flex-shrink: 0;
  opacity: 0;
  pointer-events: none;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s, background .1s, border-color .1s;
}
.msg-group:hover .msg-pin-btn,
.msg-group:focus-within .msg-pin-btn {
  opacity: 1;
  pointer-events: auto;
}
.msg-pin-btn:hover { background: var(--border); }
.msg-pin-btn.active {
  opacity: 1;
  pointer-events: auto;
  border-color: var(--accent);
  background: rgba(88, 101, 242, 0.2);
}
.msg-jump-highlight {
  animation: msgJumpPulse 1.2s ease;
}
@keyframes msgJumpPulse {
  0% { transform: scale(1.005); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

/* ---- Sticker modal ---- */
.sticker-modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0,0,0,.6);
  z-index: 500;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 40px 16px;
  box-sizing: border-box;
}
.sticker-modal-overlay.open { display: block; }
.sticker-modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  width: min(1180px, calc(100vw - 32px));
  max-width: 100%;
  max-height: min(90vh, 860px);
  margin: 0 auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.smd-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-shrink: 0;
}
.smd-header h3 { margin: 0; }
.smd-pack-summary {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}
.smd-close { padding: 4px 8px; font-size: 16px; }
.smd-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 360px);
  gap: 16px;
  min-height: 0;
  flex: 1 1 auto;
}
.smd-grid-pane,
.smd-detail-pane {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,.02);
}
.smd-grid-pane {
  display: flex;
  flex-direction: column;
  padding: 14px;
}
.smd-detail-pane {
  overflow-y: auto;
  padding: 14px;
}
.smd-pane-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}
.smd-pane-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.smd-pane-actions [aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--text);
  background: var(--surface2);
}
.smd-pane-head h4,
.smd-detail-title h4,
.smd-keyword-head h4 {
  margin: 0;
  font-size: 15px;
}
.smd-muted,
.smd-keyword-head span,
.smd-detail-title span {
  color: var(--text-muted);
  font-size: 12px;
}
.smd-stickers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  grid-auto-rows: auto;
  gap: 10px;
  min-height: 180px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 4px 2px 2px;
  align-content: start;
  flex: 1 1 auto;
  min-width: 0;
}
.smd-stickers > * { min-width: 0; }
.admin-sticker-card {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: var(--surface);
  cursor: pointer;
  outline: none;
  transition: border-color .15s, background .15s, transform .15s;
}
.admin-sticker-card:hover,
.admin-sticker-card:focus-visible {
  border-color: var(--accent);
}
.admin-sticker-card.selected {
  border-color: var(--accent);
  background: var(--surface2);
  transform: translateY(-1px);
}
.admin-sticker-preview {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 8px;
  background: #fff;
}
.admin-sticker-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(237, 66, 69, .95);
  color: #fff;
  border: none;
  font-size: 12px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.admin-sticker-delete:hover { background: #c03537; }
.admin-sticker-card-meta {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  align-items: center;
}
.admin-sticker-card-meta span {
  min-width: 0;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.25;
}
.smd-empty,
.smd-detail-empty {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.4;
}
.smd-detail-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  text-align: center;
  padding: 24px;
}
.smd-detail-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.smd-detail-preview {
  width: min(100%, 260px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}
.smd-detail-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.smd-detail-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.smd-detail-actions button {
  width: 100%;
}
.smd-danger-action {
  color: #ff9da0;
}
.smd-keyword-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 4px;
}
.smd-keyword-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.admin-sticker-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.admin-sticker-keyword-chip {
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-sticker-keyword-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}
.admin-sticker-keyword-empty {
  color: var(--text-muted);
  font-size: 12px;
}
.admin-sticker-keyword-input {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  font-size: 13px;
}
.smd-keyword-save {
  width: 100%;
}
.admin-sticker-keyword-status {
  min-height: 16px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.25;
}
.admin-sticker-keyword-status.error {
  color: #ff9da0;
}
.smd-upload-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
  flex-shrink: 0;
  background: var(--surface);
  position: relative;
  z-index: 1;
}
.smd-file-input { flex: 1 1 240px; min-width: 180px; font-size: 13px; }
.smd-upload-status {
  min-height: 18px;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12px;
}
.smd-footer {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  flex-shrink: 0;
  margin-top: 14px;
  background: var(--surface);
  position: relative;
  z-index: 1;
}
.smd-published-label { font-size: 13px; color: var(--text-muted); cursor: pointer; }
.smd-footer-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-left: auto;
}
.smd-save { padding: 6px 14px; }

.sticker-preview-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 800;
}
.sticker-preview-lightbox.open {
  display: block;
}
.sticker-preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.72);
}
.sticker-preview-panel {
  position: relative;
  width: min(520px, calc(100vw - 32px));
  margin: min(9vh, 72px) auto 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0,0,0,.42);
}
.sticker-preview-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.sticker-preview-head h3 {
  margin: 0;
  font-size: 18px;
}
.sticker-preview-head p {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 12px;
}
.sticker-preview-stage {
  width: min(100%, 420px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 10px;
  background: #fff;
}
.sticker-preview-media {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@media (max-width: 820px) {
  .sticker-modal-overlay {
    padding: 16px 8px;
  }
  .sticker-modal-box {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 32px);
    padding: 14px;
  }
  .smd-layout {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .smd-grid-pane,
  .smd-detail-pane {
    overflow: visible;
  }
  .smd-stickers {
    max-height: 42vh;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  }
  .smd-pane-head,
  .smd-footer {
    align-items: stretch;
  }
  .smd-pane-head {
    flex-direction: column;
  }
  .smd-pane-head button,
  .smd-pane-actions,
  .smd-footer-actions,
  .smd-footer-actions button {
    width: 100%;
  }
  .smd-detail-preview {
    width: min(100%, 220px);
  }
}

/* ---- Admin pagination ---- */
.admin-pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin: 10px 0;
}
.admin-pagination[hidden] {
  display: none;
}
.admin-pagination-status,
.admin-pagination-page {
  color: var(--text-muted);
  font-size: 13px;
}
.admin-pagination-status {
  margin-right: auto;
}

/* ---- Media browser ---- */
.media-browser {
  position: fixed;
  inset: 0;
  z-index: 1200;
}
.media-browser-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.68);
}
.media-browser-panel {
  position: absolute;
  top: 24px;
  right: 24px;
  bottom: 24px;
  width: min(560px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.38);
  overflow: hidden;
}
.media-browser-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.media-browser-header h2 {
  font-size: 18px;
  margin-bottom: 3px;
}
.media-browser-header p {
  color: var(--text-muted);
  font-size: 12px;
}
.media-browser-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.media-browser-tab {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  white-space: nowrap;
  font-size: 12px;
}
.media-browser-tab.active {
  background: var(--accent);
  border-color: var(--accent);
}
.media-browser-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 18px 18px;
  overflow: hidden;
}
.media-browser-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.media-browser-item {
  border: 1px solid var(--border);
  background: var(--surface2);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.media-browser-item.expired {
  opacity: 0.82;
}
.media-browser-thumb,
.media-browser-thumb-placeholder {
  width: 92px;
  height: 92px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
}
.media-browser-content {
  flex: 1;
  min-width: 0;
}
.media-browser-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.media-browser-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
  word-break: break-word;
}
.media-browser-snippet,
.media-browser-links {
  font-size: 13px;
  color: var(--text-muted);
  word-break: break-word;
}
.media-browser-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}
.media-browser-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.media-browser-badge {
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  padding: 3px 8px;
}
.media-browser-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.media-browser-action {
  min-width: 92px;
  font-size: 12px;
  padding: 8px 10px;
}
.media-browser-empty,
.media-browser-loading {
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
}
.media-browser-empty {
  border: 1px dashed var(--border);
}

@media (max-width: 920px) {
  .media-browser-panel {
    top: 10px;
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
  }
  .media-browser-item {
    flex-direction: column;
  }
  .media-browser-actions {
    width: 100%;
    flex-direction: row;
  }
  .media-browser-action {
    flex: 1;
    min-width: 0;
  }
}

/* ---- Util ---- */
.hidden { display: none !important; }
.mt8 { margin-top: 8px; }
