:root {
  --bg: #090b12;
  --panel: #101421;
  --panel-soft: #151b2c;
  --line: #252c43;
  --text: #edf1ff;
  --muted: #9aa5c2;
  --blue: #5f8cff;
  --violet: #8d75ff;
  --danger: #ff5368;
  --success: #4dd6a7;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
}

.auth-page,
.profile-page {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #090b12;
  overflow-y: auto;
  scrollbar-width: none;
}

.profile-page::-webkit-scrollbar {
  display: none;
}

.auth-panel,
.profile-editor {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font-weight: 800;
  font-size: 22px;
}

.brand-mark.compact {
  font-size: 18px;
}

.brand-mark img,
.friend-row img,
.self-row img,
.request-row img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.auth-form,
.editor-form {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

.avatar-form {
  align-items: start;
}

.auth-form h1,
.editor-head h1,
.chat-head h1,
.friends-pane h1,
.profile-editor h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

input,
textarea {
  width: 100%;
  color: var(--text);
  background: #0c101a;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  padding: 12px 13px;
}

input[type="file"] {
  padding: 10px;
  color: var(--muted);
}

input:focus,
textarea:focus {
  border-color: var(--blue);
}

textarea {
  resize: none;
}

.primary-button,
.send-button,
.accept-button,
.ghost-button {
  border: 0;
  border-radius: var(--radius);
  min-height: 40px;
  padding: 0 14px;
  color: var(--text);
  background: var(--blue);
  cursor: pointer;
  font-weight: 700;
}

.send-button {
  background: var(--violet);
}

.accept-button {
  background: var(--success);
  color: #07120f;
}

.ghost-button {
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.ghost-button.small {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.switch-auth {
  margin: 18px 0 0;
  color: var(--muted);
}

.switch-auth a {
  color: var(--blue);
}

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

.flash {
  border-radius: var(--radius);
  padding: 10px 12px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--panel-soft);
}

.flash.error {
  color: #ffc3cb;
  border-color: #6b2733;
  background: #221018;
}

.flash.success {
  color: #c9ffe8;
  border-color: #1f624f;
  background: #0d1c19;
}

.app-shell {
  height: 100svh;
  display: grid;
  grid-template-columns: minmax(220px, 25%) minmax(320px, 50%) minmax(220px, 25%);
  overflow: hidden;
}

.friend-rail,
.profile-rail,
.chat-pane,
.friends-pane {
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.profile-rail {
  border-right: 0;
  border-left: 1px solid var(--line);
  padding: 28px;
}

.friend-rail {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.rail-head {
  padding: 18px;
  display: grid;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.top-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.top-nav a {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 38px;
  border-radius: var(--radius);
  color: var(--muted);
  background: #0c101a;
}

.top-nav a.active {
  color: var(--text);
  background: var(--panel-soft);
}

.request-dot {
  position: absolute;
  right: 9px;
  top: 8px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
}

.friend-list,
.messages,
.friends-pane {
  overflow-y: auto;
  scrollbar-width: none;
}

.friend-list::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.friends-pane::-webkit-scrollbar {
  display: none;
}

.friend-list {
  padding: 12px;
}

.friend-row,
.self-row,
.request-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  border-radius: var(--radius);
  padding: 8px;
  color: var(--muted);
}

.friend-row:hover,
.friend-row.selected {
  color: var(--text);
  background: var(--panel-soft);
}

.self-row {
  border-top: 1px solid var(--line);
  background: #0c101a;
  border-radius: 0;
  padding: 12px;
}

.self-row span,
.friend-row span,
.request-row span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.friend-row span,
.self-row span,
.request-row span {
  display: grid;
  gap: 1px;
}

.friend-row strong,
.self-row strong,
.request-row strong {
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.friend-row small,
.self-row small,
.request-row small,
.profile-username {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.settings-link {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: var(--muted);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.mobile-settings {
  display: none;
}

.self-row form {
  margin-left: auto;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
}

.chat-head {
  min-height: 78px;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  display: block;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 5px;
}

.messages {
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  position: relative;
  width: fit-content;
  max-width: min(560px, 86%);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.message.mine {
  align-self: flex-end;
  background: #182141;
  border-color: #33416e;
}

.message-author {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.message p {
  margin: 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-image {
  margin-top: 8px;
  max-width: 100%;
  max-height: 360px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  object-fit: contain;
}

.message-gif {
  margin-top: 8px;
  max-width: 100%;
  max-height: 360px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #05070d;
}

.message-menu-button {
  position: absolute;
  right: 6px;
  top: 6px;
  display: none;
  width: 28px;
  height: 24px;
  border: 0;
  border-radius: var(--radius);
  color: var(--muted);
  background: #0c101a;
  cursor: pointer;
}

.message:hover .message-menu-button {
  display: block;
}

.reaction-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.reaction-pill {
  min-width: 34px;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #0c101a;
  color: var(--muted);
  font-size: 12px;
}

.reaction-pill.mine {
  color: var(--text);
  border-color: var(--violet);
}

.reaction-menu {
  position: fixed;
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(3, 38px);
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0c101a;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.reaction-menu button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: var(--radius);
  background: var(--panel-soft);
  cursor: pointer;
}

.composer {
  position: relative;
  margin: 12px 18px 18px;
  display: grid;
  grid-template-columns: 42px 1fr 48px 42px auto;
  gap: 8px;
  align-items: center;
}

.composer textarea[name="message"] {
  min-height: 46px;
  max-height: 138px;
  border-radius: var(--radius);
  padding-right: 12px;
  resize: none;
  line-height: 1.35;
}

.file-button,
.emoji-button,
.gif-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: 22px;
}

.gif-button {
  width: 48px;
  font-size: 13px;
  font-weight: 800;
}

.file-button input {
  display: none;
}

.emoji-button {
  font-size: 18px;
}

.emoji-popover {
  position: absolute;
  right: 94px;
  bottom: 54px;
  display: none;
  width: min(420px, calc(100vw - 28px));
  max-height: 360px;
  grid-template-rows: auto 1fr;
  gap: 6px;
  padding: 8px;
  background: #0c101a;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.emoji-popover.open {
  display: grid;
}

.emoji-search {
  min-height: 38px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 6px;
  overflow-y: auto;
  scrollbar-width: none;
}

.emoji-grid::-webkit-scrollbar {
  display: none;
}

.emoji-popover button {
  border: 0;
  min-width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--panel-soft);
  cursor: pointer;
}

.emoji-suggestions {
  position: absolute;
  left: 58px;
  bottom: 54px;
  width: min(320px, calc(100vw - 72px));
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0c101a;
  z-index: 30;
}

.emoji-suggestions button {
  display: flex;
  width: 100%;
  gap: 8px;
  align-items: center;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  padding: 8px;
  cursor: pointer;
}

.emoji-suggestions button.selected,
.emoji-suggestions button:hover {
  background: var(--panel-soft);
}

.attachment-name {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  padding: 0 4px;
}

.gif-popover {
  position: absolute;
  right: 86px;
  bottom: 54px;
  width: min(440px, calc(100vw - 28px));
  max-height: 420px;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0c101a;
  z-index: 35;
}

.gif-tabs {
  display: flex;
  gap: 8px;
}

.gif-tabs button,
.gif-tabs label {
  min-height: 32px;
}

.gif-results {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  overflow-y: auto;
  max-height: 280px;
  scrollbar-width: none;
}

.gif-results::-webkit-scrollbar {
  display: none;
}

.gif-result {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel-soft);
  cursor: pointer;
}

.gif-result img,
.gif-result video {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.gif-favorite {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: rgba(8, 10, 18, 0.78);
  color: var(--text);
  cursor: pointer;
}

.load-more-button {
  align-self: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--muted);
  padding: 8px 12px;
  cursor: pointer;
}

.custom-file-label span {
  display: grid;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0c101a;
  color: var(--text);
}

.custom-file-label input {
  display: none;
}

.profile-avatar {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--line);
  background: var(--panel-soft);
}

.profile-rail h2 {
  margin: 16px 0 2px;
  overflow-wrap: anywhere;
}

.profile-rail .eyebrow {
  margin-top: 18px;
}

.profile-rail p {
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.empty-state {
  color: var(--muted);
  margin: 12px;
}

.empty-state.center {
  margin: auto;
}

.friends-layout {
  grid-template-columns: minmax(220px, 25%) minmax(320px, 75%);
}

.friends-pane {
  padding-bottom: 28px;
}

.add-friend {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 10px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.request-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  padding: 22px 24px;
}

.request-columns section {
  min-width: 0;
}

.request-columns h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.request-row {
  background: #0c101a;
  border: 1px solid var(--line);
  margin-bottom: 8px;
}

.request-row > small {
  margin-left: auto;
  color: var(--muted);
}

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.editor-head a {
  color: var(--muted);
}

@media (max-width: 900px) {
  .app-shell,
  .friends-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .friend-rail {
    grid-template-rows: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .rail-head {
    padding: 12px;
    grid-template-columns: auto 1fr auto;
    align-items: center;
  }

  .mobile-settings {
    display: grid;
  }

  .friend-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 8px 12px;
  }

  .friend-row {
    min-width: 132px;
  }

  .self-row,
  .profile-rail {
    display: none;
  }

  .chat-pane {
    min-height: 0;
  }

  .chat-head {
    min-height: 64px;
    padding: 14px 16px;
  }

  .messages {
    padding: 16px;
  }

  .composer {
    grid-template-columns: 42px 1fr 48px 42px;
    margin: 10px 12px 12px;
  }

  .send-button {
    grid-column: 1 / -1;
  }

  .friends-pane {
    min-height: 0;
  }

  .add-friend,
  .request-columns {
    grid-template-columns: 1fr;
    padding: 16px;
  }
}

@media (max-width: 520px) {
  .auth-page,
  .profile-page {
    padding: 12px;
  }

  .auth-panel,
  .profile-editor {
    padding: 18px;
  }

  .brand-mark.compact span {
    display: none;
  }

  .top-nav a {
    font-size: 13px;
  }

  .friend-row {
    min-width: 108px;
  }

  .message {
    max-width: 94%;
  }
}
