.chat-page {
  background: linear-gradient(180deg, #f7f1ea 0%, #f3ece4 100%);
}

.is-hidden {
  display: none !important;
}

.chat-shell {
  padding-top: 8.5rem;
  padding-bottom: 4rem;
}

.chat-mobile-only {
  display: none;
}

.chat-login {
  max-width: 430px;
  margin: 5vh auto 0;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 22px 42px rgba(38, 24, 28, 0.12);
  padding: 2rem;
}

.chat-login h1 {
  margin: 0.4rem 0 1.2rem;
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(2rem, 4vw, 2.8rem);
}

.chat-login-form,
.chat-composer {
  display: grid;
  gap: 0.9rem;
}

.chat-switch-btn {
  margin-top: 0.6rem;
}

.chat-login-form label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.8rem;
  letter-spacing: 0.08rem;
  text-transform: uppercase;
}

.chat-login-form input,
#chat-message-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
}

.chat-status {
  min-height: 1.1rem;
  font-size: 0.85rem;
  color: rgba(45, 35, 38, 0.75);
}

.chat-btn {
  border: 0;
  background: rgba(45, 35, 38, 0.92);
  color: #fff;
  border-radius: 999px;
  padding: 0.58rem 1rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.chat-btn.alt {
  background: rgba(45, 35, 38, 0.12);
  color: var(--ink);
}

.chat-app {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 24px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.8);
  min-height: 72vh;
  height: clamp(560px, 72vh, 820px);
  max-height: calc(100vh - 9.5rem);
}

.chat-sidebar {
  border-right: 1px solid var(--line);
  padding: 1rem;
  display: grid;
  grid-template-rows: auto minmax(160px, 1fr) auto minmax(120px, auto);
  gap: 0.8rem;
  background: rgba(246, 235, 227, 0.62);
  min-height: 0;
}

.chat-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.chat-account {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.chat-account-avatar {
  width: 2.4rem;
  height: 2.4rem;
  flex: 0 0 auto;
}

.chat-account-meta {
  display: grid;
  gap: 0.12rem;
  min-width: 0;
}

.chat-account-name {
  overflow: hidden;
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-presence-control {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.chat-presence-control select {
  border: 0;
  padding: 0;
  background: transparent;
  color: rgba(45, 35, 38, 0.68);
  cursor: pointer;
  font: inherit;
  font-size: 0.72rem;
}

.chat-notifications {
  display: none;
}

.chat-sidebar h2,
.chat-main-head h2 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  font-size: 1.7rem;
}

.chat-subtitle {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08rem;
  text-transform: uppercase;
  color: rgba(45, 35, 38, 0.64);
}

.chat-conversation-list {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  align-content: flex-start;
}

.chat-add-partner-form {
  display: grid;
  gap: 0.6rem;
}

.chat-add-partner-form label {
  display: grid;
  gap: 0.38rem;
  font-size: 0.72rem;
  letter-spacing: 0.08rem;
  text-transform: uppercase;
  color: rgba(45, 35, 38, 0.72);
}

.chat-add-partner-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.62rem 0.74rem;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
}

.chat-list-item {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  border-radius: 14px;
  padding: 0.65rem 0.7rem;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.chat-list-item.active {
  border-color: rgba(45, 35, 38, 0.58);
  box-shadow: 0 10px 22px rgba(38, 24, 28, 0.14);
  transform: translateY(-1px);
}

.chat-list-item-top {
  display: flex;
  justify-content: space-between;
  gap: 0.45rem;
  align-items: center;
}

.chat-list-user {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.chat-avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: 1px solid rgba(45, 35, 38, 0.22);
  background: linear-gradient(140deg, rgba(245, 225, 228, 0.95), rgba(238, 244, 250, 0.95));
  color: rgba(45, 35, 38, 0.82);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 600;
  overflow: hidden;
}

.chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-list-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-unread {
  min-width: 1.3rem;
  height: 1.3rem;
  border-radius: 999px;
  background: #d58d93;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
}

.chat-list-preview {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: rgba(45, 35, 38, 0.62);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  min-width: 0;
  min-height: 0;
}

.chat-main-head {
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.chat-peer-status,
.chat-typing {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  color: rgba(45, 35, 38, 0.62);
}

.chat-list-presence {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.15rem;
  font-size: 0.68rem;
  line-height: 1.2;
  color: rgba(45, 35, 38, 0.58);
}

.presence-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.presence-dot.online {
  background: #22c55e;
}

.presence-dot.away {
  background: #eab308;
}

.presence-dot.busy {
  background: #ef4444;
}

.presence-dot.available {
  background: #3b82f6;
}

.presence-dot.offline {
  background: #9ca3af;
}

.chat-message-list {
  padding: 1rem;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: max-content;
  align-content: start;
  gap: 0.7rem;
}

.chat-bubble {
  width: fit-content;
  max-width: min(75%, 520px);
  min-width: 0;
  box-sizing: border-box;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.65rem 0.78rem;
  background: #fff;
  justify-self: start;
}

.chat-bubble-body {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-bubble.mine {
  justify-self: end;
  background: #f4e5e7;
}

.chat-bubble.deleted {
  font-style: italic;
  color: rgba(45, 35, 38, 0.6);
}

.chat-bubble-head {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.72rem;
  color: rgba(45, 35, 38, 0.6);
  margin-bottom: 0.25rem;
}

.chat-bubble img {
  width: min(280px, 100%);
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: zoom-in;
}

.chat-bubble-actions {
  margin-top: 0.42rem;
}

.chat-delete-btn {
  border: 0;
  background: transparent;
  color: rgba(45, 35, 38, 0.58);
  cursor: pointer;
  font-size: 0.72rem;
  padding: 0;
}

.chat-composer {
  border-top: 1px solid var(--line);
  padding: 0.85rem 1rem;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 0.55rem;
  position: relative;
  overflow: visible;
}

.chat-icon-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}

.chat-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(16, 14, 14, 0.88);
  z-index: 120;
  display: grid;
  place-items: center;
}

.chat-lightbox img {
  max-width: min(92vw, 1280px);
  max-height: 82vh;
  border-radius: 14px;
}

.chat-lightbox button {
  position: absolute;
  top: 1.2rem;
  right: 1.2rem;
  border: 0;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
}

@media (max-width: 920px) {
  #chat-message-input,
  .chat-add-partner-form input,
  .chat-login-form input {
    font-size: 16px;
  }

  .chat-main {
    position: relative;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
  }

  #chat-send-status {
    display: none;
    position: absolute;
    right: 1rem;
    bottom: 4.2rem;
    max-width: calc(100% - 2rem);
    min-height: 0;
    margin: 0;
    padding: 0.35rem 0.55rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 4px 12px rgba(38, 24, 28, 0.12);
    font-size: 0.72rem;
    z-index: 4;
  }

  #chat-send-status:not(:empty) {
    display: block;
  }

  .chat-app {
    display: block;
    position: relative;
    min-height: 74vh;
    height: 74vh;
    max-height: calc(100vh - 7rem);
  }

  .chat-sidebar,
  .chat-main {
    position: absolute;
    inset: 0;
    transition: transform 0.28s ease, opacity 0.28s ease;
  }

  .chat-sidebar {
    border-right: 0;
    border-bottom: 0;
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
    z-index: 2;
  }

  .chat-main {
    z-index: 3;
    transform: translateX(100%);
    opacity: 0;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.9);
  }

  .chat-app.chat-mobile-main .chat-sidebar {
    transform: translateX(-12%);
    opacity: 0;
    pointer-events: none;
  }

  .chat-app.chat-mobile-main .chat-main {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }

  .chat-sidebar {
    grid-template-rows: auto auto minmax(160px, 1fr) auto minmax(120px, auto);
  }

  .chat-mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

@media (max-width: 920px) and (hover: none) and (pointer: coarse) {
  .chat-notifications {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
  }

  .chat-notifications .chat-btn {
    flex: 0 0 auto;
    padding: 0.42rem 0.72rem;
    font-size: 0.72rem;
  }

  .chat-notifications .chat-status {
    min-height: 0;
    margin: 0;
    font-size: 0.72rem;
    line-height: 1.3;
  }
}

@media (max-width: 920px) {
  .chat-page.chat-active {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .chat-page.chat-active .site-header,
  .chat-page.chat-active .site-footer {
    display: none;
  }

  .chat-page.chat-active .chat-shell {
    position: fixed;
    top: var(--chat-viewport-offset-top, 0px);
    right: 0;
    bottom: auto;
    left: 0;
    width: 100%;
    height: var(--chat-viewport-height, 100dvh);
    margin: 0;
    padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  }

  .chat-page.chat-active .chat-app {
    height: 100%;
    min-height: 0;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .chat-page.chat-active .chat-message-list,
  .chat-page.chat-active .chat-conversation-list {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}

.chat-emoji-wrap {
  position: relative;
  overflow: visible;
}

.chat-emoji-picker {
  position: absolute;
  bottom: calc(100% + 0.6rem);
  left: 0;
  width: 280px;
  max-height: 220px;
  padding: 0.6rem;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.25rem;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(45, 35, 38, 0.14);
  z-index: 9999;
}

.chat-emoji-picker.is-hidden {
  display: none;
}

.chat-emoji-picker button {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 7px;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.chat-emoji-picker button:hover {
  background: rgba(45, 35, 38, 0.08);
  transform: scale(1.12);
}
