:root {
  --app-bg: #111b21;
  --sidebar-bg: #111b21;
  --header-bg: #202c33;
  --composer-bg: #202c33;
  --field-bg: #2a3942;
  --chat-bg: #0b141a;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --hover: #202c33;
  --active: #2a3942;
  --line: rgba(255,255,255,.06);
  --text: #e9edef;
  --muted: #8696a0;
  --soft: #d1d7db;
  --accent: #00a884;
  --accent-light: #00d084;
  --danger: #f15c6d;
  --blue-check: #53bdeb;
  --shadow: 0 1px 2px rgba(0,0,0,.32);
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  color: var(--text);
  background: var(--app-bg);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hidden {
  display: none !important;
}

/* AUTH */

.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(180deg, var(--accent) 0 220px, #0b141a 220px 100%);
}

.auth-card {
  width: min(430px, 100%);
  margin-top: 60px;
  padding: 32px;
  border-radius: 8px;
  background: #202c33;
  box-shadow: 0 12px 45px rgba(0,0,0,.35);
}

.brand-mark,
.empty-logo {
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: var(--accent);
  font-weight: 700;
}

.brand-mark {
  width: 66px;
  height: 66px;
  margin: -65px auto 20px;
  border: 6px solid #202c33;
  font-size: 27px;
}

.auth-card h1,
.auth-card > p {
  text-align: center;
}

.auth-card h1 {
  margin: 0;
  font-size: 24px;
}

.auth-card > p {
  margin: 8px 0 26px;
  color: var(--muted);
}

.auth-card label {
  display: block;
  margin-bottom: 15px;
}

.auth-card label span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.auth-card input {
  width: 100%;
  height: 46px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  outline: none;
  color: var(--text);
  background: #111b21;
}

.auth-card input:focus {
  border-color: var(--accent);
}

.primary-button {
  width: 100%;
  height: 46px;
  border: 0;
  border-radius: 7px;
  color: white;
  background: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

.primary-button:disabled {
  opacity: .6;
  cursor: wait;
}

.error-text {
  min-height: 20px;
  margin-top: 10px;
  color: var(--danger);
  text-align: center;
}

.auth-card small {
  display: block;
  color: var(--muted);
  text-align: center;
}

/* APP LAYOUT */

.messenger {
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(340px, 32.5%) minmax(0, 1fr);
  overflow: hidden;
  background: var(--app-bg);
}

.sidebar,
.chat-pane {
  min-width: 0;
  min-height: 0;
  height: 100dvh;
  max-height: 100dvh;
}

.sidebar {
  position: relative;
  display: grid;
  grid-template-rows: 60px 56px minmax(0, 1fr);
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--sidebar-bg);
}

.chat-pane {
  position: relative;
  display: grid;
  grid-template-rows: 60px minmax(0, 1fr) auto;
  overflow: hidden;
  background-color: var(--chat-bg);
  background-image:
    linear-gradient(rgba(11,20,26,.93), rgba(11,20,26,.93)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'%3E%3Cg fill='none' stroke='%238696a0' stroke-opacity='.12' stroke-width='1.2'%3E%3Cpath d='M18 24h32v23H18zM31 14v10M21 70c0-9 7-16 16-16s16 7 16 16-7 16-16 16-16-7-16-16zM83 24l16 16-16 16-16-16zM136 16c12 0 22 10 22 22s-10 22-22 22-22-10-22-22 10-22 22-22zM190 20h28M204 6v28M17 126c17-23 38-23 55 0M25 110h38M93 101h40v28H93zM145 98l22 11-22 11zM190 99c16 0 28 12 28 28h-56c0-16 12-28 28-28zM23 185l18-18 18 18-18 18zM84 166h35v35H84zM143 172c12 0 21 9 21 21s-9 21-21 21-21-9-21-21 9-21 21-21zM190 170h26v32h-26z'/%3E%3C/g%3E%3C/svg%3E");
}

/* SHARED */

.avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  overflow: hidden;
  color: #fff;
  background: linear-gradient(145deg, #00a884, #1689b8);
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
}

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

.icon-button,
.composer-icon,
.composer-action,
.viewer-action,
.record-delete,
.record-pause,
.record-send,
.voice-play {
  display: grid;
  place-items: center;
  border: 0;
  cursor: pointer;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--soft);
  background: transparent;
}

.icon-button:hover {
  background: rgba(255,255,255,.06);
}

/* SIDEBAR */

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--header-bg);
}

.sidebar-top-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.sidebar-search-block {
  display: flex;
  align-items: center;
  padding: 7px 12px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--sidebar-bg);
}

.search-box {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--header-bg);
}

.search-box svg {
  width: 19px;
  height: 19px;
  color: var(--muted);
}

.search-box input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: none;
  color: var(--text);
  background: transparent;
}

.search-box input::placeholder,
.composer-field textarea::placeholder {
  color: var(--muted);
}

.chat-list {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.1) transparent;
}

.chat-list::-webkit-scrollbar,
.message-area::-webkit-scrollbar,
.viewer-scroll::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

.chat-list::-webkit-scrollbar-thumb,
.message-area::-webkit-scrollbar-thumb,
.viewer-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255,255,255,.09);
}

.chat-list::-webkit-scrollbar-track,
.message-area::-webkit-scrollbar-track,
.viewer-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.chat-item,
.search-user {
  width: 100%;
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 10px 13px;
  border: 0;
  color: var(--text);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.chat-item:hover,
.search-user:hover {
  background: rgba(255,255,255,.035);
}

.chat-item.active {
  background: var(--active);
}

.chat-item-content,
.search-user-content {
  min-width: 0;
  flex: 1;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-bottom: 1px solid var(--line);
}

.chat-item.active .chat-item-content {
  border-bottom-color: transparent;
}

.chat-item-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-name {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 500;
}

.chat-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.chat-preview {
  min-width: 0;
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
}

.search-results {
  position: absolute;
  z-index: 20;
  inset: 116px 0 0;
  overflow-y: auto;
  background: var(--sidebar-bg);
}

.search-user-content strong {
  font-size: 15px;
}

.search-user-content span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.empty-list,
.loading {
  padding: 26px 18px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

/* CHAT HEADER */

.chat-header {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px 9px 16px;
  background: var(--header-bg);
}

.chat-header-info {
  min-width: 0;
  flex: 1;
  border: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: default;
}

.chat-header-info strong,
.chat-header-info span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-info strong {
  font-size: 15px;
  font-weight: 600;
}

.chat-header-info span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.mobile-back {
  display: none;
}

/* EMPTY STATE */

.empty-state {
  min-height: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.empty-logo {
  width: 90px;
  height: 90px;
  margin-bottom: 22px;
  background: #202c33;
  color: var(--muted);
  font-size: 32px;
}

.empty-state h2 {
  margin: 0;
  color: var(--soft);
  font-size: 28px;
  font-weight: 400;
}

.empty-state p {
  margin: 12px 0 0;
}

/* MESSAGE AREA */

.message-area {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 18px clamp(18px, 6vw, 86px) 14px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.08) transparent;
}

.message-row {
  width: 100%;
  display: flex;
  margin: 3px 0;
}

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

.message-bubble {
  position: relative;
  max-width: min(690px, 76%);
  padding: 7px 9px 18px;
  border-radius: 8px;
  color: var(--text);
  background: var(--bubble-in);
  box-shadow: var(--shadow);
}

.message-row.mine .message-bubble {
  background: var(--bubble-out);
}

.message-bubble::before {
  content: "";
  position: absolute;
  top: 0;
  left: -7px;
  border-width: 0 8px 8px 0;
  border-style: solid;
  border-color: transparent var(--bubble-in) transparent transparent;
}

.message-row.mine .message-bubble::before {
  right: -7px;
  left: auto;
  border-width: 0 0 8px 8px;
  border-color: transparent transparent transparent var(--bubble-out);
}

.message-text {
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.42;
}

.message-time {
  position: absolute;
  right: 7px;
  bottom: 4px;
  color: rgba(233,237,239,.62);
  font-size: 10.5px;
  line-height: 1;
}

.message-row.mine .message-time {
  color: rgba(233,237,239,.7);
}

.message-check {
  margin-left: 3px;
  color: var(--blue-check);
}

/* MEDIA */

.message-bubble.has-media {
  padding: 4px 4px 19px;
}

.message-bubble.has-media .message-text {
  padding: 7px 7px 1px;
}

.media-image-button {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  border-radius: 7px;
  overflow: hidden;
  background: transparent;
  cursor: pointer;
}

.message-image {
  display: block;
  width: min(430px, 100%);
  max-height: 520px;
  border-radius: 7px;
  object-fit: contain;
  background: rgba(0,0,0,.22);
}

.message-video {
  display: block;
  width: min(460px, 100%);
  max-height: 520px;
  border-radius: 7px;
  background: #000;
}

.message-file {
  min-width: min(330px, 65vw);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 7px;
  color: var(--text);
  text-decoration: none;
  background: rgba(0,0,0,.15);
}

.file-circle {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255,255,255,.12);
}

.file-circle svg {
  width: 21px;
  height: 21px;
}

.file-details {
  min-width: 0;
  flex: 1;
}

.file-details strong,
.file-details small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-details small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.file-download {
  color: var(--soft);
}

/* CUSTOM VOICE PLAYER */

.voice-message {
  width: min(370px, 68vw);
  min-height: 56px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 10px;
  padding: 5px 7px 1px;
}

.voice-play {
  grid-row: 1 / span 2;
  align-self: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: white;
  background: var(--accent);
}

.voice-play:hover {
  filter: brightness(1.08);
}

.voice-play svg {
  width: 18px;
  height: 18px;
  margin-left: 2px;
  fill: currentColor;
  stroke: none;
}

.voice-play.playing svg {
  margin-left: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
}

.voice-track-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 4px;
}

.voice-waveform {
  position: relative;
  min-width: 0;
  height: 25px;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}

.voice-bar {
  width: 3px;
  flex: 1 1 3px;
  max-width: 4px;
  min-width: 2px;
  border-radius: 999px;
  background: rgba(233,237,239,.38);
  transition: background .12s ease;
}

.voice-bar.played {
  background: var(--accent-light);
}

.voice-speed {
  flex: 0 0 auto;
  border: 0;
  padding: 3px 4px;
  border-radius: 5px;
  color: var(--soft);
  background: rgba(0,0,0,.16);
  font-size: 11px;
  cursor: pointer;
}

.voice-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  color: rgba(233,237,239,.62);
  font-size: 10.5px;
}

.voice-audio {
  display: none;
}

/* COMPOSER */

.composer {
  min-height: 62px;
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
  background: var(--composer-bg);
}

.composer-icon {
  width: 40px;
  height: 42px;
  flex: 0 0 auto;
  color: var(--muted);
  background: transparent;
}

.composer-icon:hover {
  color: var(--soft);
}

.composer-field {
  min-width: 0;
  min-height: 42px;
  max-height: 126px;
  flex: 1;
  display: flex;
  align-items: center;
  border-radius: 8px;
  background: var(--field-bg);
}

.composer-field textarea {
  width: 100%;
  min-height: 42px;
  max-height: 126px;
  border: 0;
  outline: none;
  resize: none;
  padding: 11px 12px 9px;
  overflow-y: auto;
  color: var(--text);
  background: transparent;
  line-height: 1.45;
}

.composer-action {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 50%;
  color: var(--soft);
  background: transparent;
}

.composer-action.has-text {
  color: white;
  background: var(--accent);
}

.action-svg {
  width: 23px;
  height: 23px;
}

.composer-action.has-text #sendIcon {
  margin-left: 2px;
}

.upload-status {
  position: absolute;
  z-index: 15;
  right: 16px;
  bottom: 72px;
  max-width: min(390px, calc(100% - 32px));
  padding: 9px 13px;
  border-radius: 7px;
  color: var(--soft);
  background: #202c33;
  box-shadow: 0 5px 22px rgba(0,0,0,.3);
  font-size: 12px;
}

.upload-status.error {
  color: #ffd2d7;
}

/* RECORD BAR */

.record-bar {
  min-height: 62px;
  display: grid;
  grid-template-columns: 42px 78px minmax(0, 1fr) 42px 42px;
  align-items: center;
  gap: 10px;
  padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
  background: var(--composer-bg);
}

.record-delete,
.record-pause,
.record-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
}

.record-delete {
  color: var(--danger);
  background: transparent;
}

.record-pause {
  color: #ff8fa0;
  background: transparent;
}

.record-send {
  color: #111b21;
  background: #fff;
}

.record-send svg {
  margin-left: 2px;
  fill: currentColor;
  stroke: none;
}

.record-timer {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--soft);
  font-size: 14px;
}

.record-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ff7185;
  animation: recordBlink 1s infinite;
}

.record-wave {
  min-width: 0;
  height: 30px;
  display: flex;
  align-items: center;
  gap: 3px;
  overflow: hidden;
}

.record-wave i {
  width: 3px;
  flex: 1 1 3px;
  max-width: 4px;
  min-width: 2px;
  border-radius: 999px;
  background: rgba(233,237,239,.4);
  animation: recordWave 1.05s ease-in-out infinite;
}

.record-wave i:nth-child(3n + 1) { height: 30%; animation-delay: -.6s; }
.record-wave i:nth-child(3n + 2) { height: 70%; animation-delay: -.3s; }
.record-wave i:nth-child(3n) { height: 48%; animation-delay: -.9s; }

.record-wave.paused i {
  animation-play-state: paused;
  opacity: .5;
}

@keyframes recordBlink {
  50% { opacity: .25; }
}

@keyframes recordWave {
  0%, 100% { transform: scaleY(.6); }
  50% { transform: scaleY(1.1); }
}

/* VIEWER */

body.viewer-open {
  overflow: hidden;
}

.media-viewer {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
  color: #fff;
  background: rgba(5,9,12,.97);
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 8px 12px 8px 19px;
  border-bottom: 1px solid var(--line);
  background: rgba(17,27,33,.94);
}

.viewer-heading {
  min-width: 0;
}

.viewer-heading strong,
.viewer-heading span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-heading span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.viewer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.viewer-action {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: var(--soft);
  background: transparent;
  text-decoration: none;
}

.viewer-action:hover {
  background: rgba(255,255,255,.07);
}

.viewer-scroll {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 22px 72px;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y pinch-zoom;
}

.viewer-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  cursor: zoom-in;
}

.media-viewer.zoomed .viewer-scroll {
  display: block;
  text-align: center;
}

.media-viewer.zoomed .viewer-image {
  min-width: min(1500px, 175vw);
  max-width: none;
  max-height: none;
  margin: 0 auto;
  cursor: zoom-out;
}

.viewer-nav {
  position: fixed;
  z-index: 3;
  top: 50%;
  width: 50px;
  height: 76px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: rgba(255,255,255,.07);
  font-size: 50px;
  line-height: 1;
  cursor: pointer;
}

.viewer-nav:hover {
  background: rgba(255,255,255,.13);
}

.viewer-nav:disabled {
  display: none;
}

.viewer-prev { left: 10px; }
.viewer-next { right: 10px; }

/* MOBILE */

@media (max-width: 900px) {
  .messenger {
    display: block;
    position: relative;
  }

  .sidebar,
  .chat-pane {
    position: absolute;
    inset: 0;
    width: 100%;
  }

  .chat-pane {
    transform: translateX(100%);
    transition: transform .2s ease;
  }

  .messenger.chat-open .chat-pane {
    transform: translateX(0);
  }

  .messenger.chat-open .sidebar {
    visibility: hidden;
  }

  .mobile-back {
    display: grid;
  }

  .message-area {
    padding: 13px 9px 10px;
  }

  .message-bubble {
    max-width: 87%;
  }

  .chat-header {
    padding-left: 5px;
  }

  .chat-header-actions .icon-button:nth-child(3) {
    display: none;
  }

  .composer {
    gap: 3px;
    padding-inline: 7px;
  }

  .composer-icon {
    width: 35px;
  }

  #emojiButton {
    display: none;
  }

  .record-bar {
    grid-template-columns: 40px 66px minmax(0, 1fr) 40px 42px;
    gap: 5px;
    padding-inline: 7px;
  }

  .viewer-scroll {
    padding: 10px 6px calc(10px + env(safe-area-inset-bottom));
  }

  .viewer-nav {
    display: none;
  }

  .media-viewer.zoomed .viewer-image {
    min-width: 185vw;
  }
}

@media (max-width: 460px) {
  .sidebar-search-block {
    padding-inline: 8px;
  }

  .chat-item,
  .search-user {
    padding-inline: 10px;
  }

  .voice-message {
    width: min(315px, 76vw);
  }

  .message-file {
    min-width: min(290px, 76vw);
  }

  .record-timer {
    font-size: 12px;
  }
}
