.msg-body { overflow: hidden; }

.page-nav__actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.msg-app {
  position: relative;
  z-index: 1;
  display: flex;
  width: min(1100px, 100%);
  height: calc(100dvh - 4.2rem);
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(165deg, #181620 0%, #100f15 100%);
  box-shadow: var(--inset-shadow), var(--matte-elev);
}

.msg-sidebar {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: rgba(8, 7, 12, 0.55);
}

.msg-sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 1rem 0.65rem;
  border-bottom: 1px solid var(--border);
}

.msg-sidebar__tools {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.msg-sidebar__title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

.msg-icon-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-inset);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.msg-search {
  padding: 0 1rem 0.65rem;
}

.msg-search-results {
  margin-top: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 160px;
  overflow: auto;
}

.msg-chat-list {
  flex: 1;
  overflow: auto;
  padding: 0 0.5rem 0.5rem;
}

.msg-sidebar.is-settings .msg-chat-list,
.msg-sidebar.is-settings .msg-search,
.msg-sidebar.is-settings .msg-promo,
.msg-sidebar.is-settings .msg-profile {
  display: none !important;
}

.msg-settings {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.msg-settings[hidden] {
  display: none !important;
}

.msg-sidebar.is-settings .msg-settings:not([hidden]) {
  display: flex;
}

.msg-chat-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.msg-chat-row:hover,
.msg-chat-row.is-active {
  background: rgba(255, 255, 255, 0.04);
}

.msg-chat-row__avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-inset);
}

.msg-chat-row__body { min-width: 0; flex: 1; }
.msg-chat-row__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.msg-chat-row__title {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}
.msg-chat-row__time {
  flex-shrink: 0;
  font-size: 0.58rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.msg-chat-row__preview {
  display: block;
  font-size: 0.62rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.15rem;
}

.msg-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.msg-empty[hidden],
.msg-chat[hidden],
.msg-settings[hidden] {
  display: none !important;
}

.msg-main:not(.has-chat) .msg-chat {
  display: none !important;
}

.msg-main.has-chat .msg-empty {
  display: none !important;
}

.msg-main.has-chat .msg-chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.msg-empty {
  flex: 1;
  display: grid;
  place-content: center;
  gap: 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 2rem;
}

.msg-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0 1rem 1rem;
}

.msg-chat__head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.msg-back-mobile {
  display: none;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem;
}

.msg-chat__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.msg-chat__titles { min-width: 0; flex: 1; }
.msg-chat__title {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-chat__subtitle {
  font-size: 0.58rem;
  color: var(--muted);
}

.msg-chat__actions {
  display: flex;
  gap: 0.35rem;
}

.msg-chat .chat-messages {
  flex: 1;
  min-height: 0;
  margin: 0.75rem 0;
}

.msg-profile {
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.65rem;
}

.msg-profile__row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
}

.msg-profile__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.msg-profile__name { display: block; font-weight: 600; }
.msg-profile__user { display: block; color: var(--muted); font-size: 0.58rem; }

.msg-profile__upload {
  display: inline-block;
  color: var(--purple-soft);
  cursor: pointer;
}

.msg-promo {
  margin: 0.5rem 1rem 0.75rem;
  padding: 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-inset);
  font-size: 0.65rem;
  line-height: 1.45;
}

.msg-promo a {
  color: var(--purple-soft);
}

.search-user-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.45rem 0.55rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-inset);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  flex-direction: column;
  display: none;
}

.call-overlay:not([hidden]) {
  display: flex;
}

.call-remote {
  flex: 1;
  width: 100%;
  object-fit: cover;
  background: #111;
}

.call-local {
  position: absolute;
  right: 1rem;
  bottom: 5rem;
  width: 120px;
  height: 160px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.call-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: rgba(0, 0, 0, 0.85);
  color: var(--text);
  font-size: 0.72rem;
}

.call-bar__controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.call-control-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.call-control-btn.is-off {
  opacity: 0.45;
  background: rgba(255, 80, 80, 0.25);
}

.call-control-btn--hangup {
  background: rgba(220, 50, 50, 0.85);
  border-color: transparent;
}

.call-incoming {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.72);
}

.call-incoming:not([hidden]) {
  display: flex;
}

.call-incoming[hidden] {
  display: none !important;
}

.call-incoming__card {
  width: min(100%, 320px);
  padding: 1.5rem 1.25rem;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}

.call-incoming__avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 0.75rem;
  display: block;
  background: var(--surface-inset);
}

.call-incoming__label {
  margin: 0 0 0.35rem;
  font-size: 0.68rem;
  color: var(--muted);
}

.call-incoming__name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.call-incoming__user {
  margin: 0.2rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
}

.call-incoming__kind {
  margin: 0.75rem 0 1.25rem;
  font-size: 0.78rem;
  color: var(--text);
}

.call-incoming__actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.call-incoming__btn {
  flex: 1;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: none;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.call-incoming__btn--decline {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.call-incoming__btn--accept {
  background: rgba(80, 180, 120, 0.85);
  color: #fff;
}

.msg-settings__field { margin-top: 1rem; }
.msg-settings__username-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.msg-settings__username-prefix {
  color: var(--muted);
  font-size: 0.78rem;
}
.msg-settings__username-input { flex: 1; min-width: 0; }
.msg-settings__btn--compact {
  padding: 0.45rem 0.65rem;
  font-size: 0.68rem;
  white-space: nowrap;
}

.chat-msg--call {
  align-self: center;
  max-width: 85%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-msg--call .chat-msg__body {
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
}

.chat-msg--call .chat-msg__meta {
  justify-content: center;
}

.msg-settings__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

.msg-settings__title {
  margin: 0;
  font: 600 0.95rem/1.2 var(--font-display, inherit);
}

.msg-settings__body {
  flex: 1;
  overflow: auto;
  padding: 0.75rem 0.9rem 1rem;
}

.msg-settings__section {
  margin-bottom: 1.1rem;
}

.msg-settings__label {
  margin: 0 0 0.55rem;
  font: 600 0.72rem/1.2 var(--font-mono, inherit);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.msg-settings__hint {
  margin: 0 0 0.65rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.msg-settings__btn {
  display: block;
  width: 100%;
  margin-top: 0.55rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-inset);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.msg-settings__btn--danger {
  border-color: rgba(255, 90, 90, 0.35);
  color: #ff8a8a;
}

.msg-sessions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.msg-session-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-inset);
}

.msg-session-row__meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.72rem;
}

.msg-session-row__device {
  font-weight: 600;
}

.msg-session-row__sub {
  color: var(--text-muted);
}

.msg-session-row__badge {
  font-size: 0.62rem;
  color: var(--accent, #9b87ff);
}

.msg-session-row__revoke {
  flex-shrink: 0;
  padding: 0.25rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.68rem;
  cursor: pointer;
}

@media (max-width: 760px) {
  .msg-app {
    height: calc(100dvh - 3.6rem);
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .msg-sidebar {
    width: 100%;
    position: absolute;
    inset: 0;
    z-index: 2;
    transition: transform 0.2s ease;
  }

  .msg-app.chat-open .msg-sidebar {
    transform: translateX(-100%);
  }

  .msg-back-mobile { display: block; }

  .page-nav__actions .page-nav__link:first-child { display: none; }
}
