:root {
  color-scheme: dark;
  --bg: #0e1621;
  --bg-alt: #111a24;
  --panel: #17212b;
  --panel-2: #1f2c3a;
  --panel-3: #243447;
  --text: #e7eef6;
  --muted: #8a9bb0;
  --muted-2: #5c6e81;
  --accent: #2ea6ff;
  --accent-2: #4fbeff;
  --danger: #ff6464;
  --bubble-me: #2b5278;
  --bubble-them: #1f2c3a;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  --radius: 12px;
  --radius-sm: 10px;
  --ease: 180ms ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(46, 166, 255, 0.08), transparent 25%),
    linear-gradient(180deg, #101923 0%, #0b1118 100%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

body {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
textarea {
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: rgba(46, 166, 255, 0.75);
  box-shadow: 0 0 0 2px rgba(46, 166, 255, 0.18);
}

#app {
  width: 100%;
  height: 100%;
}

.auth {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
  overflow: hidden;
}

.auth__panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: 40px;
  background: linear-gradient(180deg, rgba(23, 33, 43, 0.98), rgba(15, 23, 33, 0.98));
  border-right: 1px solid var(--border);
}

.auth__art {
  position: relative;
  background:
    linear-gradient(145deg, rgba(46, 166, 255, 0.16), transparent 52%),
    linear-gradient(180deg, #182433 0%, #0d141d 100%);
}

.auth__brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(180deg, #3bb3ff, #1d93f3);
  box-shadow: 0 12px 30px rgba(29, 147, 243, 0.38);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand-mark svg {
  width: 24px;
  height: 24px;
  fill: white;
}

.auth__title {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.05;
  max-width: 12ch;
}

.auth__subtitle {
  margin: 0;
  max-width: 42ch;
  color: var(--muted);
  line-height: 1.55;
}

.auth-card {
  width: min(100%, 420px);
  padding: 22px;
  border-radius: 18px;
  background: rgba(23, 33, 43, 0.92);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

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

.tab {
  flex: 1;
  border: 0;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 12px 14px;
  transition: background var(--ease), color var(--ease), transform var(--ease);
}

.tab.is-active {
  background: rgba(46, 166, 255, 0.18);
  color: var(--text);
}

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

.field {
  display: grid;
  gap: 8px;
}

.field label {
  font-size: 13px;
  color: var(--muted);
}

.field input,
.field textarea {
  width: 100%;
  padding: 12px 14px;
}

.auth-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
}

.primary,
.secondary,
.ghost,
.icon-button {
  border: 0;
  border-radius: 10px;
  transition: transform var(--ease), background var(--ease), color var(--ease), opacity var(--ease);
}

.primary {
  background: linear-gradient(180deg, #2ea6ff, #2495ea);
  color: white;
  padding: 12px 16px;
  font-weight: 600;
  box-shadow: 0 10px 22px rgba(36, 149, 234, 0.28);
}

.secondary {
  background: var(--panel-2);
  color: var(--text);
  padding: 11px 14px;
}

.ghost {
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  color: var(--text);
}

.sidebar__new-chat {
  width: 42px;
  height: 42px;
  flex: none;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.icon-button#hangup-btn svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.15;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.primary:hover,
.secondary:hover,
.ghost:hover,
.icon-button:hover,
.tab:hover {
  transform: translateY(-1px);
}

.primary:active,
.secondary:active,
.ghost:active,
.icon-button:active,
.tab:active {
  transform: translateY(0);
}

.error {
  min-height: 20px;
  color: #ff9a9a;
  font-size: 13px;
}

.shell {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-columns: 340px 1fr;
  background: rgba(11, 17, 24, 0.5);
}

.sidebar {
  background: linear-gradient(180deg, rgba(23, 33, 43, 0.98), rgba(17, 26, 36, 0.98));
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px 12px;
}

.sidebar__title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sidebar__title strong {
  font-size: 16px;
}

.sidebar__title span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.sidebar__search {
  padding: 0 16px 12px;
  display: grid;
  gap: 10px;
}

.sidebar__search-row {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
  align-items: center;
}

.sidebar__search input {
  width: 100%;
  padding: 12px 14px;
}

.search-results,
.thread-list {
  display: grid;
  gap: 8px;
  padding: 0 12px 14px;
  overflow: auto;
}

.section-label {
  padding: 10px 4px 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.thread-item,
.user-item {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: transparent;
  border: 0;
  color: var(--text);
  border-radius: 12px;
  transition: background var(--ease);
}

.thread-item:hover,
.user-item:hover,
.thread-item.is-active {
  background: rgba(255, 255, 255, 0.05);
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 700;
  flex: none;
  overflow: hidden;
}

.avatar--button {
  border: 0;
  padding: 0;
  background: inherit;
  cursor: pointer;
  position: relative;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
  transition: transform var(--ease), box-shadow var(--ease);
}

.avatar--button:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 0 1px rgba(46, 166, 255, 0.25);
}

.avatar--editable {
  isolation: isolate;
}

.avatar__edit {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(10, 20, 31, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #f5f9ff;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.avatar__edit svg {
  width: 10px;
  height: 10px;
  stroke: currentColor;
  fill: none;
}

.avatar__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thread-item__meta,
.user-item__meta {
  min-width: 0;
  display: grid;
  gap: 3px;
  flex: 1;
}

.thread-item__title,
.user-item__title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-item__preview,
.user-item__preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-item__time {
  color: var(--muted-2);
  font-size: 12px;
}

.main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  position: relative;
}

.chat-header {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(18, 27, 37, 0.92);
  border-bottom: 1px solid var(--border);
}

.chat-header__title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.chat-header__title strong {
  font-size: 16px;
}

.chat-header__title span {
  color: var(--muted);
  font-size: 12px;
}

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

.stage {
  position: relative;
  display: none;
  gap: 10px;
  padding: 14px 16px 0;
  background: rgba(14, 22, 33, 0.88);
}

.stage.is-visible {
  display: grid;
}

.video-grid {
  display: grid;
  grid-template-columns: 1fr minmax(180px, 220px);
  gap: 12px;
  min-height: 220px;
}

.video-box {
  position: relative;
  min-height: 220px;
  border-radius: 14px;
  overflow: hidden;
  background: #060c13;
  border: 1px solid var(--border);
}

.video-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #060c13;
}

.video-box--local {
  min-height: 160px;
}

.call-banner {
  position: absolute;
  inset: 18px auto auto 18px;
  z-index: 3;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(23, 33, 43, 0.92);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
}

.call-banner strong {
  font-size: 14px;
}

.call-banner span {
  color: var(--muted);
  font-size: 12px;
}

.messages {
  overflow-y: scroll;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  padding: 16px 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(56, 177, 255, 0.88) rgba(255, 255, 255, 0.08);
  overscroll-behavior: contain;
}

.messages::-webkit-scrollbar {
  width: 12px;
}

.messages::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
}

.messages::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(58, 179, 255, 0.96), rgba(30, 145, 232, 0.96));
  border-radius: 999px;
  border: 2px solid rgba(15, 23, 33, 0.94);
  min-height: 44px;
}

.messages::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(72, 188, 255, 1), rgba(35, 155, 245, 1));
}

.messages__empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 40px;
}

.message {
  max-width: min(720px, 84%);
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--bubble-them);
  border: 1px solid rgba(255, 255, 255, 0.04);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.message.is-me {
  align-self: flex-end;
  background: var(--bubble-me);
}

.message__body {
  white-space: pre-wrap;
  line-height: 1.45;
  word-break: break-word;
}

.message__meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
  color: rgba(255, 255, 255, 0.65);
  font-size: 11px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 10px 16px 12px;
  background: rgba(18, 27, 37, 0.92);
  border-top: 1px solid var(--border);
}

.composer textarea {
  resize: none;
  height: 46px;
  min-height: 46px;
  max-height: 46px;
  padding: 13px 14px;
  line-height: 1.25;
  overflow-y: auto;
}

.composer textarea::placeholder {
  color: var(--muted-2);
}

.composer__actions {
  display: flex;
  gap: 10px;
  align-items: end;
}

.composer-tool {
  width: 46px;
  height: 46px;
  border-radius: 14px;
}

.send-button {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #2ea6ff, #1f93eb);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 22px rgba(36, 149, 234, 0.28);
}

.send-button svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  transform: translateX(1px);
}

.send-button:hover {
  transform: translateY(-1px);
}

.send-button:active {
  transform: translateY(0);
}

.emoji-picker {
  display: none;
  position: absolute;
  right: 12px;
  bottom: 76px;
  width: min(360px, calc(100% - 24px));
  padding: 8px;
  border-radius: 14px;
  background: rgba(23, 33, 43, 0.98);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.emoji-picker.is-open {
  display: block;
}

.emoji-picker__grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
}

.emoji-chip {
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: white;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-size: 17px;
}

.emoji-chip:hover {
  background: rgba(255, 255, 255, 0.09);
}

.picker-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 8px;
}

.picker-tabs {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.picker-tab {
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
  font-size: 12px;
}

.picker-tab.is-active {
  background: rgba(46, 166, 255, 0.18);
  color: var(--text);
}

.picker-body {
  overflow: hidden;
}

.gif-picker__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.gif-chip {
  border: 0;
  padding: 6px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  display: grid;
  gap: 6px;
  text-align: left;
}

.gif-chip img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
}

.gif-chip span {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.gif-chip:hover {
  background: rgba(255, 255, 255, 0.08);
}

.message__media {
  display: grid;
  gap: 8px;
}

.message__gif {
  display: block;
  max-width: 280px;
  width: 100%;
  border-radius: 12px;
}

.message__caption {
  white-space: pre-wrap;
  line-height: 1.45;
  word-break: break-word;
}

.status-pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  font-size: 12px;
}

.mobile-only {
  display: none;
}

@media (max-width: 980px) {
  .auth {
    grid-template-columns: 1fr;
  }

  .auth__art {
    display: none;
  }

  .shell {
    grid-template-columns: 1fr;
    position: relative;
  }

  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    transform: translateX(-100%);
    transition: transform 220ms ease;
    z-index: 20;
    box-shadow: 24px 0 40px rgba(0, 0, 0, 0.35);
  }

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

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

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

  .video-box--local {
    min-height: 130px;
  }

  .message {
    max-width: 92%;
  }

  .emoji-picker__grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .gif-picker__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .emoji-picker {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: 70px;
  }
}
