:root {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #111827;
  --panel-soft: #1f2937;
  --border: rgba(148, 163, 184, 0.16);
  --text: #e5edf9;
  --muted: #93a2b7;
  --accent: #2d6cdf;
  --accent-strong: #1d4ed8;
  --incoming: #1f2937;
  --outgoing: #1d4ed8;
  --success: #22c55e;
  --danger: #ef4444;
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(45, 108, 223, 0.25), transparent 24%),
    linear-gradient(180deg, #0b1220 0%, #111827 100%);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

textarea {
  resize: vertical;
}

.hidden {
  display: none !important;
}

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: min(100%, 420px);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.brand h1,
.chat-header h3,
.sidebar-top h2,
.profile-title-block h3 {
  margin: 0;
}

.brand p,
.chat-header p,
.eyebrow,
.profile-presence,
.profile-username {
  margin: 4px 0 0;
  color: var(--muted);
}

.brand-badge {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), #60a5fa);
  font-size: 1.4rem;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.tab,
.ghost-button,
.text-button,
.secondary-button,
.avatar-button,
.modal-close-button,
.avatar-upload-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab {
  padding: 10px 14px;
  border-radius: 12px;
}

.tab.active {
  background: rgba(45, 108, 223, 0.18);
  color: var(--text);
}

.auth-form,
.profile-section {
  display: grid;
  gap: 14px;
}

.auth-form label,
.profile-section label {
  display: grid;
  gap: 8px;
}

.auth-form input,
.composer input,
.search-input,
.profile-section input,
.profile-section textarea {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(31, 41, 55, 0.85);
  color: var(--text);
  outline: none;
}

.auth-form input:focus,
.composer input:focus,
.search-input:focus,
.profile-section input:focus,
.profile-section textarea:focus {
  border-color: rgba(96, 165, 250, 0.6);
}

.primary-button,
.secondary-button {
  padding: 14px 18px;
  border-radius: 14px;
  font-weight: 600;
}

.primary-button {
  border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  cursor: pointer;
}

.secondary-button {
  border: 1px solid var(--border);
  background: rgba(31, 41, 55, 0.75);
  color: var(--text);
}

.auth-error,
.profile-form-status {
  min-height: 20px;
  margin: 0;
  color: #fca5a5;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  border-right: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(16px);
  padding: 18px 16px 16px;
  min-height: 0;
  overflow: hidden;
}

.sidebar-top,
.sidebar-heading,
.composer,
.current-user-block,
.chat-header-content,
.profile-modal-header,
.profile-avatar-stack,
.profile-actions {
  display: flex;
  align-items: center;
}

.sidebar-top,
.sidebar-heading {
  justify-content: space-between;
}

.sidebar-actions,
.selected-members {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sidebar-top {
  gap: 16px;
  margin-bottom: 22px;
}

.current-user-block,
.chat-header-content {
  gap: 14px;
}

.current-user-profile-button,
#chat-profile-button {
  flex: 0 0 auto;
}

.desktop-update-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(31, 41, 55, 0.65);
}

.desktop-update-copy {
  display: grid;
  gap: 6px;
}

.desktop-update-status {
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.45;
}

.desktop-update-actions,
.profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.sidebar-section {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
  min-height: 0;
}

.search-panel {
  position: relative;
  display: grid;
  gap: 10px;
  padding-bottom: 2px;
}

.search-label {
  color: var(--muted);
  font-size: 0.88rem;
}

.user-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.search-results {
  display: grid;
  gap: 8px;
}

.search-panel > .search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 15;
  max-height: 280px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(17, 24, 39, 0.98);
  box-shadow: 0 20px 44px rgba(15, 23, 42, 0.32);
}

.sidebar-heading {
  color: var(--muted);
  font-size: 0.95rem;
  padding-top: 8px;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
}

.user-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px;
  border: 1px solid transparent;
  border-radius: 18px;
  background: rgba(31, 41, 55, 0.72);
  color: var(--text);
  text-align: left;
  position: relative;
}

.user-item.active {
  border-color: rgba(96, 165, 250, 0.38);
  background: rgba(45, 108, 223, 0.16);
}

.search-item {
  padding: 12px 14px;
}

.user-item-main {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
  background: transparent;
  border: 0;
  color: inherit;
  padding: 0;
  text-align: left;
}

.user-item-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.user-item-lower {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.user-item-status {
  font-size: 0.88rem;
  color: var(--muted);
}

.user-item-preview {
  font-size: 0.86rem;
  color: rgba(229, 237, 249, 0.82);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-item-name {
  display: grid;
  gap: 3px;
}

.user-handle {
  color: var(--muted);
  font-size: 0.84rem;
}

.chat-item-side {
  display: grid;
  gap: 8px;
  align-items: center;
  justify-items: end;
  flex: 0 0 auto;
}

.chat-item-top-meta,
.chat-item-bottom-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-item-time {
  min-width: 42px;
  text-align: right;
  color: var(--muted);
  font-size: 0.76rem;
}

.chat-type-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  color: var(--text);
  font-size: 0.72rem;
}

.unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
}

.unread-badge.muted {
  background: rgba(148, 163, 184, 0.28);
  color: var(--text);
}

.chat-options-button {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(15, 23, 42, 0.55);
}

.chat-options-menu {
  position: absolute;
  top: calc(100% - 8px);
  right: 12px;
  z-index: 12;
  min-width: 176px;
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(17, 24, 39, 0.98);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.34);
}

.chat-options-item {
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
}

.chat-options-item:hover {
  background: rgba(45, 108, 223, 0.16);
}

.avatar-button {
  padding: 0;
  line-height: 0;
}

.avatar-shell,
.profile-avatar-shell {
  position: relative;
}

.avatar-placeholder,
.avatar-image {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.avatar-placeholder {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(45, 108, 223, 0.9), rgba(96, 165, 250, 0.85));
  color: white;
  font-weight: 700;
}

.avatar-image {
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.avatar-placeholder-large,
.avatar-image-large {
  width: 52px;
  height: 52px;
}

.avatar-placeholder-xl,
.avatar-image-xl {
  width: 108px;
  height: 108px;
  font-size: 2rem;
}

.presence-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.online-dot,
.offline-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.online-dot {
  background: var(--success);
}

.offline-dot {
  background: rgba(148, 163, 184, 0.45);
}

.search-status {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(31, 41, 55, 0.6);
  color: var(--muted);
  font-size: 0.92rem;
}

.chat-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.chat-header {
  padding: 24px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.74);
  backdrop-filter: blur(12px);
}

.chat-header-tools {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.pinned-message {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(31, 41, 55, 0.55);
  cursor: pointer;
}

.pinned-message p,
.pinned-message strong {
  margin: 0;
}

.chat-search-panel {
  position: relative;
}

.chat-search-results {
  position: absolute;
  inset: calc(100% + 8px) 0 auto;
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.96);
  z-index: 8;
}

.group-modal-card {
  width: min(100%, 620px);
}

.selected-member-chip {
  border: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(45, 108, 223, 0.18);
  color: var(--text);
  cursor: pointer;
}

.chat-search-result {
  border: 0;
  padding: 10px 12px;
  border-radius: 12px;
  text-align: left;
  background: rgba(31, 41, 55, 0.8);
  color: var(--text);
  cursor: pointer;
}

.message-list {
  padding: 24px 28px;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 0;
}

.message {
  max-width: min(72%, 720px);
  padding: 14px 16px;
  border-radius: 18px;
  box-shadow: 0 14px 24px rgba(15, 23, 42, 0.18);
}

.message.incoming {
  background: var(--incoming);
  border-bottom-left-radius: 8px;
}

.message.outgoing {
  margin-left: auto;
  background: var(--outgoing);
  border-bottom-right-radius: 8px;
}

.message-time {
  margin-top: 8px;
  font-size: 0.8rem;
  opacity: 0.75;
}

.message-status {
  margin-top: 4px;
  font-size: 0.78rem;
  opacity: 0.8;
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-body mark {
  padding: 0 2px;
  border-radius: 4px;
  background: rgba(96, 165, 250, 0.35);
  color: var(--text);
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.message-reply-preview,
.message-image-button {
  display: block;
  width: 100%;
  border: 0;
  padding: 10px 12px;
  border-radius: 14px;
  text-align: left;
  background: rgba(15, 23, 42, 0.22);
  color: var(--muted);
  cursor: pointer;
}

.message-image-button {
  padding: 0;
  overflow: hidden;
}

.message-image {
  display: block;
  max-width: 100%;
  max-height: 320px;
  object-fit: cover;
}

.message-file {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.24);
}

.message-file-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.message-highlight {
  outline: 2px solid rgba(96, 165, 250, 0.65);
  transition: outline-color 0.8s ease;
}

.empty-state {
  margin: auto;
  color: var(--muted);
  text-align: center;
}

.composer {
  display: grid;
  gap: 14px;
  padding: 18px 24px 24px;
  border-top: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.92);
}

.composer-context {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(31, 41, 55, 0.7);
}

.composer-context p,
.composer-context strong {
  margin: 0;
}

.composer-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.composer input {
  flex: 1;
}

.attachment-button {
  flex: 0 0 auto;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(31, 41, 55, 0.85);
  cursor: pointer;
}

.new-messages-button {
  position: absolute;
  right: 32px;
  bottom: 108px;
  z-index: 5;
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.28);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.75);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  width: min(100%, 540px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 28px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.98);
  box-shadow: var(--shadow);
}

.image-modal-card {
  width: min(100%, 820px);
}

.image-modal-image {
  width: 100%;
  max-height: calc(100vh - 180px);
  object-fit: contain;
  border-radius: 18px;
}

.modal-close-button {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: rgba(31, 41, 55, 0.8);
  color: var(--text);
  font-size: 1.35rem;
}

.profile-modal-card {
  display: grid;
  gap: 18px;
}

.profile-modal-header {
  align-items: flex-start;
  gap: 20px;
}

.profile-avatar-stack {
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

.avatar-upload-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(45, 108, 223, 0.16);
  color: var(--text);
}

.avatar-upload-button input {
  display: none;
}

.profile-avatar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.profile-title-block {
  display: grid;
  gap: 6px;
}

.profile-bio {
  margin: 0;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(31, 41, 55, 0.7);
  color: var(--text);
  line-height: 1.55;
}

.profile-meta-list {
  display: grid;
  gap: 10px;
}

.profile-meta-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(31, 41, 55, 0.62);
}

.profile-meta-label {
  color: var(--muted);
}

.group-members-list {
  display: grid;
  gap: 10px;
}

.group-member-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(31, 41, 55, 0.62);
}

.group-member-meta {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}

.group-member-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.group-member-owner-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.18);
  color: var(--text);
  font-size: 0.75rem;
}

.group-member-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.avatar-crop-modal-card {
  width: min(100%, 860px);
}

.avatar-crop-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 22px;
  align-items: start;
}

.avatar-crop-stage {
  display: grid;
  gap: 14px;
}

.avatar-crop-frame {
  position: relative;
  width: min(100%, 460px);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 28px;
  border: 1px solid var(--border);
  background:
    linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(14, 165, 233, 0.08)),
    rgba(15, 23, 42, 0.9);
  cursor: grab;
  touch-action: none;
}

.avatar-crop-frame:active {
  cursor: grabbing;
}

.avatar-crop-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-radius: 28px;
  box-shadow: inset 0 0 0 999px rgba(2, 6, 23, 0.24);
  pointer-events: none;
}

.avatar-crop-image {
  position: absolute;
  top: 0;
  left: 0;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: top left;
}

.avatar-crop-slider {
  display: grid;
  gap: 8px;
}

.avatar-crop-preview-panel {
  display: grid;
  gap: 12px;
  justify-items: center;
  padding: 16px;
  border-radius: 20px;
  background: rgba(31, 41, 55, 0.56);
}

.avatar-crop-preview {
  width: 160px;
  height: 160px;
  border-radius: 28px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.92);
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .avatar-crop-layout {
    grid-template-columns: 1fr;
  }

  .avatar-crop-preview-panel {
    justify-items: start;
  }
}

@media (max-width: 640px) {
  .modal {
    padding: 12px;
  }

  .modal-card {
    padding: 22px 18px;
  }

  .profile-modal-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .profile-avatar-stack {
    align-items: center;
  }

  .profile-actions {
    flex-direction: column;
  }

  .profile-actions > button {
    width: 100%;
  }
}
