:root {
  --bg: #f4f2fb;
  --bg-deep: #ece7ff;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --surface-soft: #f7f3ff;
  --surface-muted: #efe9ff;
  --text: #2d2447;
  --text-soft: #6e6686;
  --border: rgba(100, 82, 176, 0.12);
  --border-strong: rgba(100, 82, 176, 0.22);
  --primary: #7057ff;
  --primary-strong: #5b3df4;
  --secondary: #ffcd4d;
  --secondary-soft: #fff2bf;
  --success: #27a77b;
  --danger: #e65d5d;
  --shadow-lg: 0 22px 64px rgba(85, 60, 170, 0.16);
  --shadow-md: 0 14px 34px rgba(85, 60, 170, 0.11);
  --shadow-sm: 0 8px 18px rgba(85, 60, 170, 0.08);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 15px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --sidebar-width: 100%;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(112, 87, 255, 0.22), transparent 32%),
    radial-gradient(circle at top right, rgba(255, 205, 77, 0.24), transparent 28%),
    linear-gradient(180deg, #f9f8ff 0%, var(--bg) 42%, #eeebf8 100%);
  color: var(--text);
  font-family: "Segoe UI Variable", "SF Pro Display", "Segoe UI", "Helvetica Neue", sans-serif;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 15px;
}

body.chat-open {
  overflow: hidden;
}

#app,
.app-shell,
.sidebar-shell,
.chat-shell,
.sidebar-panels,
.tab-panel,
.auth-hero,
.auth-card,
.list-card,
.list-item,
.chat-header,
.composer,
.message-item,
.identity-pill,
.sidebar-header,
.profile-top,
.panel-heading,
.subheading-row,
.action-row,
.invite-form,
.profile-form,
.chat-headline > div {
  min-width: 0;
  max-width: 100%;
}

button,
input,
textarea {
  font: inherit;
  min-width: 0;
}

button {
  border: 0;
}

input,
textarea {
  width: 100%;
  color: var(--text);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

input:focus,
textarea:focus {
  border-color: rgba(112, 87, 255, 0.35);
  box-shadow: 0 0 0 4px rgba(112, 87, 255, 0.12);
}

textarea {
  resize: none;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
}

.auth-screen {
  display: grid;
  align-items: center;
  padding:
    max(14px, calc(14px + var(--safe-top)))
    max(14px, calc(14px + var(--safe-right)))
    max(14px, calc(14px + var(--safe-bottom)))
    max(14px, calc(14px + var(--safe-left)));
}

.auth-hero {
  width: min(1180px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 18px;
}

.auth-copy {
  padding: 12px 4px 0;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(112, 87, 255, 0.1);
  color: var(--primary);
  border: 1px solid rgba(112, 87, 255, 0.14);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.auth-copy h1 {
  margin: 14px 0 12px;
  font-size: clamp(1.8rem, 4.8vw, 3.7rem);
  line-height: 0.98;
  max-width: 12ch;
}

.auth-copy p {
  margin: 0;
  max-width: 38rem;
  color: var(--text-soft);
  font-size: 1rem;
  line-height: 1.6;
}

.auth-card,
.list-card,
.chat-header,
.composer,
.chat-empty-state,
.sidebar-search,
.tab-switcher,
.identity-pill,
.message-item,
.invite-item {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.auth-card {
  border-radius: 28px;
  padding: 20px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.brand-mark,
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 24px;
  font-weight: 800;
  color: #fff;
  background:
    linear-gradient(145deg, rgba(255, 205, 77, 0.98), rgba(112, 87, 255, 0.98)),
    linear-gradient(145deg, #8b74ff, #5d45f5);
  box-shadow: var(--shadow-sm);
  user-select: none;
}

.brand-logo-image {
  width: 92px;
  height: auto;
  flex: 0 0 auto;
  border-radius: 22px;
  box-shadow: var(--shadow-sm);
}

.avatar-tone-0 {
  background: linear-gradient(145deg, #8f78ff, #5f46f5);
}

.avatar-tone-1 {
  background: linear-gradient(145deg, #ffcf63, #ff9c40);
}

.avatar-tone-2 {
  background: linear-gradient(145deg, #6fd8c5, #3d9ad8);
}

.avatar-tone-3 {
  background: linear-gradient(145deg, #ff8fa0, #ffb14d);
}

.avatar-tone-4 {
  background: linear-gradient(145deg, #6fb8ff, #6d74ff);
}

.avatar-tone-5 {
  background: linear-gradient(145deg, #92d66f, #39b56d);
}

.avatar-tone-6 {
  background: linear-gradient(145deg, #f6a5ff, #8d66ff);
}

.avatar-tone-7 {
  background: linear-gradient(145deg, #ffc877, #ff7f6b);
}

.avatar-tone-8 {
  background: linear-gradient(145deg, #80e0ff, #4b8cff);
}

.avatar-tone-9 {
  background: linear-gradient(145deg, #ffd95c, #b47bff);
}

.avatar-tone-10 {
  background: linear-gradient(145deg, #9bf0a6, #57c8b5);
}

.avatar-tone-11 {
  background: linear-gradient(145deg, #ffb4d2, #8d7bff);
}

.brand-mark {
  width: 66px;
  height: 66px;
  font-size: 1.8rem;
}

.avatar {
  flex: 0 0 auto;
}

.avatar-l {
  width: 46px;
  height: 46px;
  font-size: 1rem;
}

.avatar-xl {
  width: 66px;
  height: 66px;
  border-radius: 24px;
  font-size: 1.25rem;
}

.auth-card h2,
.panel-heading h3,
.subheading-row h4,
.profile-card h3,
.chat-empty-state h2 {
  margin: 0;
}

.brand-lockup p,
.panel-heading p,
.helper-text,
.chat-subtitle,
.identity-subtitle {
  margin: 0;
  color: var(--text-soft);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

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

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

.field-stack {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.auth-form span {
  color: var(--text-soft);
  font-size: 14px;
}

.field-stack span {
  color: var(--text-soft);
  font-size: 14px;
}

.primary-btn,
.ghost-btn,
.send-btn,
.icon-btn,
.bottom-btn,
.tab-btn {
  cursor: pointer;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    background-color 0.18s ease,
    color 0.18s ease,
    border-color 0.18s ease;
}

.primary-btn,
.send-btn {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  box-shadow: 0 18px 35px rgba(91, 61, 244, 0.22);
}

.primary-btn {
  border-radius: 16px;
  padding: 12px 16px;
  font-weight: 700;
}

.primary-btn.wide {
  width: 100%;
}

.ghost-btn,
.icon-btn,
.tab-btn,
.bottom-btn {
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border);
}

.ghost-btn {
  border-radius: 14px;
  padding: 11px 14px;
  font-weight: 600;
}

.ghost-btn.compact {
  padding: 9px 12px;
  border-radius: 12px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.accent {
  background: rgba(112, 87, 255, 0.12);
  color: var(--primary);
}

.primary-btn:hover,
.ghost-btn:hover,
.send-btn:hover,
.icon-btn:hover,
.tab-btn:hover,
.bottom-btn:hover {
  transform: translateY(-1px);
}

.form-error {
  color: var(--danger);
  font-weight: 600;
}

.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding:
    max(8px, calc(8px + var(--safe-top)))
    max(8px, calc(8px + var(--safe-right)))
    max(8px, calc(10px + var(--safe-bottom)))
    max(8px, calc(8px + var(--safe-left)));
}

.sidebar-shell,
.chat-shell {
  min-height: 0;
}

.sidebar-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 10px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.identity-pill {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 20px;
  padding: 10px 12px;
}

.identity-copy {
  min-width: 0;
}

.identity-title,
.chat-title,
.profile-card h3 {
  font-weight: 800;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 18px;
}

.search-icon {
  color: var(--text-soft);
}

.sidebar-search input {
  border: 0;
  box-shadow: none;
  background: transparent;
  padding: 0;
}

.tab-switcher,
.bottom-nav {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  border-radius: 18px;
  padding: 6px;
}

.tab-btn,
.bottom-btn {
  min-height: 40px;
  padding: 10px 8px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 13px;
}

.tab-btn.active,
.bottom-btn.active {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  border-color: transparent;
  box-shadow: 0 14px 28px rgba(91, 61, 244, 0.2);
}

.sidebar-panels {
  position: relative;
  min-height: 0;
}

.tab-panel {
  display: none;
  height: 100%;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fade-up 0.24s ease;
}

.panel-heading,
.subheading-row,
.action-row,
.profile-top,
.chat-headline,
.composer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading > div,
.subheading-row > div,
.profile-top > div,
.chat-headline > div,
.identity-copy {
  min-width: 0;
}

.counter-chip,
.meta-chip,
.selected-file,
.typing-indicator {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}

.counter-chip {
  background: rgba(112, 87, 255, 0.11);
  color: var(--primary);
}

.counter-chip.soft {
  background: rgba(255, 205, 77, 0.26);
  color: #876200;
}

.list-card {
  border-radius: 20px;
  padding: 13px;
}

.grow-card {
  min-height: 220px;
}

.list-stack {
  display: grid;
  gap: 8px;
}

.list-stack.compact {
  gap: 8px;
}

.list-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-radius: 17px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(112, 87, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.list-item.clickable {
  cursor: pointer;
}

.list-item.active {
  background: linear-gradient(135deg, rgba(112, 87, 255, 0.18), rgba(255, 205, 77, 0.18));
  border-color: rgba(112, 87, 255, 0.18);
}

.item-main,
.message-main {
  min-width: 0;
}

.item-title,
.message-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-bottom: 4px;
  font-weight: 700;
}

.item-title strong,
.message-title strong,
.line-clamp {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-subtitle,
.item-meta,
.message-meta {
  color: var(--text-soft);
  font-size: 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #c5c0d4;
  box-shadow: 0 0 0 4px rgba(112, 87, 255, 0.08);
}

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

.badge-count {
  min-width: 28px;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mini-btn {
  padding: 9px 11px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.mini-btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #fff;
  border-color: transparent;
}

.mini-btn.warning {
  background: var(--secondary-soft);
  color: #7b5b00;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.meta-chip {
  background: rgba(255, 255, 255, 0.72);
  color: var(--text-soft);
}

.meta-chip strong {
  display: block;
  margin-top: 6px;
  color: var(--text);
  font-size: 16px;
}

.chat-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 10px;
  min-height: calc(100vh - 16px - var(--safe-top) - var(--safe-bottom));
  min-height: calc(100dvh - 16px - var(--safe-top) - var(--safe-bottom));
  overflow: hidden;
}

.chat-header,
.composer,
.chat-empty-state {
  border-radius: 22px;
  padding: 13px;
}

.chat-header {
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.chat-subtitle {
  margin-top: 4px;
}

.chat-empty-state {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.empty-glow {
  position: absolute;
  inset: -10% auto auto -5%;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(112, 87, 255, 0.22), transparent 70%);
}

.empty-card {
  position: relative;
  z-index: 1;
  text-align: center;
  max-width: 360px;
}

.empty-badge {
  width: 60px;
  height: 60px;
  margin: 0 auto 14px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow-sm);
}

.empty-logo-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 22px;
}

.message-viewport {
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 4px 0 0;
  scroll-behavior: smooth;
}

.message-list {
  display: grid;
  gap: 10px;
  padding: 4px 0 10px;
}

.message-row {
  display: flex;
}

.message-row.mine {
  justify-content: flex-end;
}

.message-item {
  width: min(100%, 520px);
  border-radius: 19px;
  padding: 12px 13px;
}

.message-row.mine .message-item {
  background: linear-gradient(135deg, rgba(112, 87, 255, 0.18), rgba(255, 205, 77, 0.22));
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.message-attachment {
  margin-top: 10px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(112, 87, 255, 0.08);
}

.message-attachment a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 700;
}

.message-image {
  display: block;
  max-width: 100%;
  border-radius: 16px;
  margin-top: 10px;
  box-shadow: var(--shadow-sm);
}

.typing-indicator {
  justify-self: center;
  color: var(--primary);
  background: rgba(112, 87, 255, 0.1);
  flex-shrink: 0;
}

.composer {
  padding-top: 12px;
  flex-shrink: 0;
}

.selected-file {
  align-self: flex-start;
  color: #7b5b00;
  background: var(--secondary-soft);
  margin-bottom: 8px;
}

.composer-input {
  flex: 1;
  min-width: 0;
}

.composer-input textarea {
  min-height: 46px;
  max-height: 180px;
}

.send-btn {
  width: 46px;
  height: 46px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.toast-stack {
  position: fixed;
  right: 12px;
  bottom: calc(78px + var(--safe-bottom));
  z-index: 20;
  display: grid;
  gap: 10px;
  width: min(320px, calc(100vw - 24px));
}

.toast {
  background: rgba(45, 36, 71, 0.92);
  color: #fff;
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow-lg);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.hide {
  opacity: 0;
  transform: translateY(8px);
}

.mobile-only {
  display: inline-flex;
}

.desktop-hidden {
  display: inline-flex;
}

.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 4;
  padding-bottom: calc(8px + var(--safe-bottom));
}

.invite-item input {
  font-size: 13px;
}

.empty-list {
  padding: 18px 14px;
  border-radius: 18px;
  border: 1px dashed rgba(112, 87, 255, 0.18);
  color: var(--text-soft);
  text-align: center;
}

.notification-extra {
  margin-top: 8px;
}

.action-row {
  flex-wrap: wrap;
}

.action-row > * {
  min-width: 0;
}

.invite-form {
  grid-template-columns: minmax(0, 1fr) auto;
}

.profile-form-actions {
  justify-content: flex-start;
}

.invite-form > * {
  min-width: 0;
}

.form-feedback {
  margin-top: 14px;
}

.form-feedback-tight {
  margin-top: 10px;
}

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

@media (min-width: 900px) {
  :root {
    --sidebar-width: 360px;
  }

  .auth-screen {
    padding: 24px;
  }

  .auth-hero {
    grid-template-columns: minmax(0, 1.2fr) minmax(360px, 430px);
    align-items: center;
  }

  .app-shell {
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    padding: 14px;
  }

  .sidebar-shell {
    height: calc(100vh - 28px);
    height: calc(100dvh - 28px);
  }

  .chat-shell {
    height: calc(100vh - 28px);
    height: calc(100dvh - 28px);
  }

  .bottom-nav {
    display: none;
  }

  .mobile-only,
  .desktop-hidden {
    display: none;
  }

  .message-item {
    width: min(100%, 620px);
  }
}

@media (max-width: 899px) {
  body.chat-open .sidebar-shell {
    display: none;
  }

  body:not(.chat-open) .chat-shell {
    display: none;
  }

  .chat-shell {
    height: calc(100vh - 16px - var(--safe-top) - var(--safe-bottom));
    height: calc(100dvh - 16px - var(--safe-top) - var(--safe-bottom));
    min-height: 0;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .sidebar-header,
  .profile-top,
  .subheading-row,
  .action-row {
    flex-wrap: wrap;
  }

  .list-item {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
  }

  .item-actions {
    grid-column: 2;
    justify-content: flex-start;
  }

  .panel-heading,
  .subheading-row,
  .chat-headline {
    align-items: flex-start;
  }

  .sidebar-header .ghost-btn,
  .action-row .primary-btn,
  .action-row .ghost-btn,
  .profile-form-actions .primary-btn {
    width: 100%;
  }

  .profile-top {
    align-items: flex-start;
  }

  .brand-logo-image {
    width: 76px;
  }
}

@media (max-width: 420px) {
  body {
    font-size: 14px;
  }

  .auth-screen {
    padding:
      max(10px, calc(10px + var(--safe-top)))
      max(10px, calc(10px + var(--safe-right)))
      max(10px, calc(10px + var(--safe-bottom)))
      max(10px, calc(10px + var(--safe-left)));
  }

  .auth-copy h1 {
    font-size: clamp(1.55rem, 8vw, 2.2rem);
  }

  .auth-card,
  .list-card,
  .chat-header,
  .composer,
  .chat-empty-state {
    padding: 11px;
    border-radius: 18px;
  }

  .identity-pill,
  .sidebar-search,
  .tab-switcher,
  .bottom-nav {
    padding: 8px 10px;
    border-radius: 16px;
  }

  .tab-btn,
  .bottom-btn {
    font-size: 12px;
    min-height: 36px;
    padding: 8px 6px;
  }

  .avatar-l {
    width: 40px;
    height: 40px;
  }

  .icon-btn,
  .send-btn {
    width: 38px;
    height: 38px;
  }

  .composer-input textarea {
    min-height: 42px;
  }

  .empty-card {
    max-width: 280px;
  }

  .invite-form {
    grid-template-columns: 1fr;
  }
}

@supports (-webkit-touch-callout: none) {
  @media (max-width: 899px) {
    .app-shell,
    .auth-screen {
      padding-left: max(10px, calc(10px + var(--safe-left)));
      padding-right: max(10px, calc(10px + var(--safe-right)));
    }

    .sidebar-shell,
    .chat-shell,
    .tab-panel,
    .list-card,
    .list-item,
    .message-item,
    .sidebar-header,
    .profile-top,
    .subheading-row,
    .action-row {
      overflow-x: clip;
    }
  }
}

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