:root {
  --bg: #eef3f7;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #6c7a89;
  --line: #dce5ec;
  --accent: #0f8f82;
  --accent-dark: #0b6c63;
  --accent-2: #3658d4;
  --danger: #c43d4b;
  --mine: #dff4ef;
  --soft: #eef6f8;
  --shadow: 0 18px 50px rgb(25 45 70 / 0.12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  transition: background-color 0.18s ease, color 0.18s ease;
}
body.dark {
  --bg: #0d1118;
  --panel: #151c26;
  --text: #eef5fb;
  --muted: #a5b2c0;
  --line: #293545;
  --accent: #31b9a9;
  --accent-dark: #249789;
  --accent-2: #7b8cff;
  --danger: #ff7777;
  --mine: #163c38;
  --soft: #202b39;
  --shadow: 0 18px 50px rgb(0 0 0 / 0.28);
}
button, input, textarea { font: inherit; }
button {
  border: 0;
  background: var(--accent);
  color: white;
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.14s ease, background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}
button:hover { background: var(--accent-dark); }
button:active { transform: translateY(1px) scale(0.98); }
.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}
.ghost:hover { background: var(--soft); color: var(--text); }
.active-toggle {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.danger-button:hover {
  border-color: var(--danger);
  color: var(--danger);
}
.icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
}
.app-shell {
  display: grid;
  grid-template-columns: 310px 1fr;
  height: 100vh;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: background-color 0.18s ease, border-color 0.18s ease;
}
.brand, .section-title, .profile-mini, .chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { padding: 18px; border-bottom: 1px solid var(--line); }
.panel-section { padding: 14px; border-bottom: 1px solid var(--line); }
.users-section { flex: 1; overflow: auto; }
.section-title { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.list { display: grid; gap: 6px; }
.list-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  color: var(--text);
  background: transparent;
  text-align: left;
  min-height: 42px;
  border-radius: 8px;
  transition: background-color 0.14s ease, transform 0.14s ease;
}
.list-item:hover, .list-item.active { background: var(--soft); color: var(--text); }
.list-item:hover { transform: translateX(2px); }
.list-item small { margin-left: auto; color: var(--muted); }
.dot, .list-item small i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #a8b5b2;
  flex: 0 0 auto;
  display: inline-block;
  margin-right: 5px;
}
.dot.online { background: #18a058; }
.profile-mini {
  padding: 14px;
  border-top: 1px solid var(--line);
}
.profile-mini button:first-child {
  background: transparent;
  color: var(--text);
  padding-left: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.chat {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100vh;
}
.chat-header {
  padding: 16px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  justify-content: flex-start;
  transition: background-color 0.18s ease, border-color 0.18s ease;
}
.chat-header > div:first-of-type { min-width: 0; }
.chat-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}
.chat-header h1 {
  margin: 0;
  font-size: 20px;
}
.chat-title-button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  min-width: 0;
}
.chat-title-button:hover { background: transparent; color: var(--text); }
.chat-title-button span:last-child {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.chat-title-button strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status { color: var(--muted); font-size: 13px; }
.menu-button, #closeSidebar { display: none; }
.messages {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.message {
  max-width: min(720px, 90%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-wrap: anywhere;
  display: flex;
  gap: 10px;
  animation: messageIn 0.18s ease both;
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease, background-color 0.18s ease;
}
.message:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.06);
}
.message.mine {
  align-self: flex-end;
  background: var(--mine);
}
.message.mentioned {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}
.message-content { min-width: 0; }
.message p { margin: 6px 0 0; white-space: pre-wrap; }
.meta {
  display: flex;
  gap: 10px;
  align-items: baseline;
  color: var(--muted);
  font-size: 13px;
  flex-wrap: wrap;
}
.meta strong { color: var(--text); }
.message-action {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 0 2px;
  font-size: 12px;
}
.message-action:hover {
  background: transparent;
  color: var(--accent);
}
.message-action.danger:hover { color: var(--danger); }
.message.deleted {
  opacity: 0.78;
}
.deleted-text {
  color: var(--muted);
  font-style: italic;
}
.reply-preview {
  margin-top: 6px;
  padding-left: 8px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-size: 13px;
}
mark {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--text);
  border-radius: 4px;
  padding: 0 3px;
}
.context-menu {
  position: fixed;
  z-index: 30;
  width: 160px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 40px rgb(0 0 0 / 0.18);
  animation: menuIn 0.12s ease both;
}
.context-menu button {
  width: 100%;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.context-menu button:hover { background: var(--soft); }
.typing {
  min-height: 24px;
  padding: 0 18px;
  color: var(--muted);
  font-size: 14px;
}
.composer {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 10px;
  padding: 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  transition: background-color 0.18s ease, border-color 0.18s ease;
}
.reply-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--muted);
}
.reply-bar[hidden] {
  display: none !important;
}
.reply-bar button {
  width: 28px;
  height: 28px;
  padding: 0;
}
textarea, input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  resize: none;
  outline: none;
  color: var(--text);
  background: var(--panel);
}
textarea:focus, input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}
.auth-card h1 { margin: 0 0 8px; }
.auth-card p { color: var(--muted); }
.auth-form { display: grid; gap: 14px; }
.auth-form label { display: grid; gap: 6px; color: var(--muted); }
.notice { min-height: 22px; font-size: 14px; }
.notice.bad { color: var(--danger); }
.notice.good { color: var(--accent); }
dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  width: min(420px, calc(100% - 30px));
}
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
dialog[open] { animation: modalIn 0.16s ease both; }
.modal-form { padding: 22px; display: grid; gap: 14px; }
.modal-form label { display: grid; gap: 6px; color: var(--muted); }
.muted-text { color: var(--muted); margin: 0; }
.check-row {
  display: flex !important;
  grid-template-columns: none;
  align-items: center;
  gap: 10px;
}
.check-row input { width: auto; }
.danger-fill {
  background: var(--danger);
  color: white;
}
.danger-fill:hover { filter: brightness(0.92); }
.members-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}
.invite-search {
  display: grid;
  gap: 8px;
}
.invite-search[hidden] {
  display: none !important;
}
.search-results {
  display: grid;
  gap: 6px;
  max-height: 190px;
  overflow: auto;
}
.search-result {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  text-align: left;
}
.search-result:hover {
  background: var(--soft);
  color: var(--text);
}
.search-result small {
  color: var(--muted);
}
.member-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.member-row small {
  margin-left: auto;
  color: var(--muted);
}
.modal-form menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0;
  margin: 0;
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 82px;
  background: #15211f;
  color: white;
  padding: 10px 14px;
  border-radius: 6px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 0.18s ease;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(420px, calc(100vw - 28px));
  box-shadow: 0 12px 34px rgb(0 0 0 / 0.22);
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.toast button {
  width: 26px;
  height: 26px;
  padding: 0;
  background: rgb(255 255 255 / 0.12);
  color: white;
  flex: 0 0 auto;
}
.toast button:hover { background: rgb(255 255 255 / 0.22); }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: inline-grid;
  place-items: center;
  object-fit: cover;
  font-weight: 700;
  flex: 0 0 auto;
}
.avatar.small {
  width: 28px;
  height: 28px;
  font-size: 12px;
}
.avatar.large {
  width: 86px;
  height: 86px;
  font-size: 26px;
}
.avatar-preview {
  display: flex;
  justify-content: center;
}
.unread-count, .unread-dot {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  padding: 0 6px;
}
.unread-dot {
  min-width: 10px;
  width: 10px;
  height: 10px;
  padding: 0;
  background: var(--danger);
}
.media {
  display: block;
  max-width: min(520px, 100%);
  max-height: 360px;
  margin-top: 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #000;
}
.image-media {
  background: transparent;
  object-fit: contain;
}
.audio-media {
  max-height: 54px;
  background: transparent;
}
.video-preview {
  width: 100%;
  max-height: min(68vh, 520px);
  border-radius: 14px;
  background: #000;
  border: 1px solid var(--line);
}
.empty-chat {
  margin: auto;
  display: grid;
  gap: 6px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}
.empty-chat strong {
  color: var(--text);
  font-size: 18px;
}
.recording {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
  animation: pulse 1.1s ease infinite;
}
.media-icon {
  position: relative;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}
.media-icon::before,
.media-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  display: block;
}
.attach-icon::before {
  width: 16px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 8px 8px 6px 6px;
  transform: rotate(18deg);
}
.attach-icon::after {
  width: 8px;
  height: 10px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 5px 5px;
  transform: rotate(18deg) translateY(1px);
}
.mic-icon::before {
  width: 12px;
  height: 18px;
  border: 2px solid currentColor;
  border-radius: 999px;
  top: -6px;
}
.mic-icon::after {
  width: 18px;
  height: 13px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 12px 12px;
  top: 8px;
}
.video-icon::before {
  width: 17px;
  height: 13px;
  border: 2px solid currentColor;
  border-radius: 4px;
}
.video-icon::after {
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 9px solid currentColor;
  left: 20px;
}

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

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes menuIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 35%, transparent); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 0%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 86vw);
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 0 100vw rgb(0 0 0 / 0.3); }
  .menu-button, #closeSidebar { display: grid; }
  .message { max-width: 96%; }
  .composer {
    grid-template-columns: auto auto 1fr;
  }
  #sendButton { grid-column: 1 / -1; }
  .chat-actions { gap: 5px; }
}

/* Nexus visual refresh */
body {
  transition: background-color 0.18s ease, color 0.18s ease;
}

button {
  border-radius: 10px;
}

.app-shell {
  background:
    radial-gradient(circle at 12% 8%, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent 30%),
    radial-gradient(circle at 88% 14%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 28%),
    var(--bg);
}

.sidebar,
.chat-header,
.composer {
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  backdrop-filter: blur(14px);
}

.brand-lockup,
.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-lockup strong,
.auth-logo strong {
  font-size: 20px;
  letter-spacing: 0;
}

.logo-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  color: white;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 28%, transparent);
}

.logo-mark.large {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  font-size: 28px;
}

.auth-logo {
  margin-bottom: 22px;
}

.list-item {
  min-height: 46px;
  border-radius: 10px;
}

.list-item:hover,
.list-item.active {
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 14%, var(--soft)), var(--soft));
}

.chat-title-button {
  border-radius: 12px;
  padding: 6px 8px;
}

.chat-title-button:hover {
  background: var(--soft);
}

.messages {
  padding: 22px;
}

.message {
  border-radius: 16px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: 0 8px 28px rgb(20 35 52 / 0.06);
}

.message.mine {
  background: linear-gradient(135deg, var(--mine), color-mix(in srgb, var(--mine) 70%, var(--panel)));
}

.message:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 14px 34px rgb(20 35 52 / 0.10);
}

textarea,
input {
  border-radius: 12px;
}

.auth-page {
  background:
    radial-gradient(circle at 18% 18%, color-mix(in srgb, var(--accent-2) 22%, transparent), transparent 32%),
    radial-gradient(circle at 82% 20%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 28%),
    var(--bg);
}

.auth-card {
  border-radius: 20px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

dialog {
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.context-menu {
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.toast {
  border-radius: 14px;
  box-shadow: var(--shadow);
}
