html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  overscroll-behavior: none;
}

input,
textarea,
select {
  font-size: 16px;
}

.phone-shell {
  height: 100dvh;
  overflow: hidden;
}

.phone-screen {
  min-height: 0;
}

.auth-secondary-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.auth-secondary-actions .btn {
  min-height: 52px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 820;
}

.page,
.auth-page,
.profile-scroll {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.profile-page {
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  padding-bottom: 14px;
}

.profile-scroll {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  padding-bottom: calc(96px + var(--safe-bottom));
}

.profile-scroll > .menu-list--grouped {
  flex: 1 1 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.page--padded > .menu-list--grouped {
  max-height: min(46dvh, 360px);
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.profile-scroll > .menu-list--danger {
  flex: 0 0 auto;
  margin-top: 0;
}

.scroll-list-page {
  overflow: hidden;
}

.search-page {
  grid-template-rows: auto auto minmax(0, 1fr);
  padding-bottom: 0;
}

.search-controls {
  display: grid;
  align-content: start;
  gap: 16px;
  min-height: 0;
}

.search-results {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding-bottom: calc(96px + var(--safe-bottom));
}

.page:has(> .content-list) {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  padding-bottom: 0;
}

.page--padded:has(> .call-list) {
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

.page--padded:has(> .notification-list) {
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

.home-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding-bottom: 0;
}

.calls-page {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.notifications-page {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.scroll-list-page > .content-list,
.scroll-list-page > .notification-list,
.scroll-list-page > .call-list,
.scroll-list-page > .language-list,
.scroll-list-page > .preview-list,
.page:has(> .content-list) > .content-list,
.page--padded:has(> .call-list) > .call-list,
.page--padded:has(> .notification-list) > .notification-list {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding-bottom: calc(96px + var(--safe-bottom));
}

.content-list,
.notification-list,
.call-list,
.language-list,
.preview-list {
  align-content: start;
  grid-auto-rows: max-content;
}

.search-entry {
  min-height: 46px;
  height: auto;
  max-height: 58px;
}

.chat-row,
.list-row,
.notification-row,
.call-history-row,
.search-message {
  height: auto;
  align-self: start;
}

.chat-row {
  min-height: 72px;
  max-height: 92px;
}

.call-list {
  overflow-x: hidden;
  overflow-y: auto;
}

.call-history-row {
  grid-template-columns: 48px minmax(0, 1fr) minmax(118px, auto);
  grid-template-areas: "icon main side";
  min-height: 76px;
  align-items: center;
}

.call-history-icon {
  grid-area: icon;
}

.call-history-main {
  grid-area: main;
}

.call-history-side {
  grid-area: side;
  position: static;
  display: grid;
  justify-items: end;
  align-content: center;
  gap: 6px;
  min-width: 118px;
}

.call-history-side .pill,
.pill {
  position: static;
  width: auto;
  max-width: 100%;
  min-height: 26px;
  align-self: center;
  justify-self: end;
  line-height: 1;
  white-space: nowrap;
}

.call-history-side small {
  max-width: 130px;
  text-align: right;
}

.profile-card--compact {
  grid-template-columns: 64px minmax(0, 1fr);
  place-items: center start;
  min-height: 106px;
  gap: 8px 12px;
  text-align: left;
  padding: 16px;
}

.profile-card--compact .avatar {
  grid-row: 1 / span 3;
  width: 58px;
  height: 58px;
  font-size: 18px;
}

.profile-card--compact h2,
.profile-card--compact p {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notifications-toolbar {
  position: static;
  top: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
  text-align: left;
}

.permission-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 10px;
  min-height: 0;
  padding: 12px;
}

.permission-chip span {
  min-width: 0;
  white-space: normal;
  line-height: 1.25;
}

.permission-chip strong {
  justify-self: end;
  white-space: nowrap;
}

.permission-chip .btn {
  grid-column: 1 / -1;
  justify-self: start;
  min-height: 38px;
  border-radius: 14px;
  padding-inline: 14px;
}

.permission-card {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.permission-card > div {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.permission-card .btn,
.permission-card .toggle-row {
  justify-self: start;
  width: auto;
  max-width: 100%;
}

.notifications-toolbar > .btn {
  min-height: 42px;
  border-radius: 14px;
}

.call-screen {
  min-height: 0;
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  padding: 0 clamp(14px, 4vw, 22px) calc(18px + var(--safe-bottom));
}

.call-main {
  min-height: 0;
  overflow: hidden;
  align-content: start;
  gap: clamp(8px, 1.5dvh, 14px);
  padding-block: clamp(6px, 1.3dvh, 14px);
}

.call-main .avatar--call {
  width: clamp(50px, 9dvh, 80px);
  height: clamp(50px, 9dvh, 80px);
  font-size: clamp(18px, 3.4dvh, 28px);
}

.call-main h1 {
  max-width: 100%;
  margin: 0;
  font-size: clamp(28px, min(7vw, 5.8dvh), 52px);
  line-height: 1.02;
}

.call-main p {
  margin: 0;
  font-size: clamp(16px, 2.6dvh, 22px);
}

.call-timer {
  min-height: 0;
  padding: clamp(10px, 1.6dvh, 14px) clamp(22px, 5vw, 34px);
  font-size: clamp(18px, 3dvh, 24px);
}

.call-video-preview {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  width: min(74%, 310px);
  height: min(36dvh, 330px);
  min-height: 150px;
  max-height: 100%;
  background: #101827;
  border-radius: clamp(22px, 4dvh, 34px);
}

.call-video-preview__media {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
  transform: scaleX(-1);
}

.call-video-preview__media--remote {
  transform: none;
}

.call-local-preview {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  width: min(30%, 92px);
  aspect-ratio: 3 / 4;
  border: 2px solid rgba(255, 255, 255, .78);
  border-radius: 18px;
  background: #0f172a;
  box-shadow: 0 16px 34px rgba(0, 0, 0, .32);
  object-fit: cover;
  transform: scaleX(-1);
}

.call-video-preview span {
  max-width: 100%;
  padding-inline: 12px;
  text-align: center;
}

.message-bubble .media-preview {
  width: min(100%, 250px);
}

.message-bubble .media-preview--loading {
  display: grid;
  place-items: center;
  min-height: 188px;
}

.message-bubble .media-preview img,
.message-bubble .media-preview video {
  display: block;
  width: 100%;
  max-height: 220px;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #020617;
}

.composer-dock {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 35;
  display: grid;
  gap: 8px;
}

.composer-dock .composer,
.composer-dock .composer-reply {
  position: static;
  left: auto;
  right: auto;
  bottom: auto;
}

.chat-page .messages {
  padding-bottom: 176px;
  scroll-padding-bottom: 176px;
}

.chat-page--with-attachment .messages {
  padding-bottom: 244px;
  scroll-padding-bottom: 244px;
}

.chat-page--with-reply:not(.chat-page--with-attachment) .messages {
  padding-bottom: 176px;
  scroll-padding-bottom: 176px;
}

.attachment-draft {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
  border: 1px solid hsl(var(--border) / .74);
  border-radius: 18px;
  background: hsl(var(--phone) / .94);
  box-shadow: var(--shadow-floating);
  padding: 10px;
  backdrop-filter: saturate(1.35) blur(18px);
}

.attachment-draft__preview {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.attachment-draft__preview .media-preview,
.attachment-draft__preview .document-preview,
.attachment-draft__preview .audio-preview {
  width: 74px;
  height: 58px;
  max-width: 74px;
}

.attachment-draft__preview .media-preview img,
.attachment-draft__preview .media-preview video {
  width: 74px;
  height: 58px;
  object-fit: cover;
  border-radius: 12px;
}

.attachment-draft__preview .document-preview {
  display: grid;
  place-items: center;
  padding: 0;
  overflow: hidden;
  font-size: 0;
}

.attachment-draft__preview .document-preview svg {
  width: 22px;
  height: 22px;
}

.attachment-draft__preview .audio-preview {
  height: 34px;
  align-self: center;
}

.attachment-draft__preview span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.attachment-draft__preview strong,
.attachment-draft__preview small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-draft__preview small {
  color: hsl(var(--muted-foreground));
  font-size: 12px;
}

.attachment-draft input {
  min-width: 0;
  min-height: 42px;
  border: 0;
  border-radius: 14px;
  outline: 0;
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
  padding: 0 12px;
}

.attachment-draft .icon-button {
  width: 42px;
  height: 42px;
}

.message-bubble:has(.audio-preview) {
  max-width: min(78%, 260px);
  padding: 8px;
}

.audio-preview {
  width: min(210px, 100%);
  height: 34px;
}

.toast-stack {
  top: auto;
  right: max(20px, calc((100vw - 438px) / 2 - 380px));
  bottom: calc(20px + var(--safe-bottom));
  width: min(360px, calc(100vw - 40px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
}

.call-video-preview small,
.call-media-status {
  max-width: min(100%, 280px);
  margin: 0;
  color: rgba(255, 255, 255, .72);
  font-size: clamp(12px, 1.8dvh, 14px);
  font-weight: 720;
  line-height: 1.35;
  text-align: center;
}

.media-viewer-page {
  grid-template-rows: auto minmax(0, 1fr);
}

.media-viewer-page .topbar {
  color: #fff;
}

.media-viewer-page .topbar .icon-button {
  color: #fff;
  background: rgba(255, 255, 255, .12);
  border-color: rgba(255, 255, 255, .2);
}

.media-viewer .media-preview {
  width: min(100%, 720px);
  background: transparent;
}

.media-viewer img,
.media-viewer video {
  width: auto;
  max-width: 100%;
  aspect-ratio: auto;
  object-fit: contain;
}

.call-media-status--connected {
  color: rgba(187, 247, 208, .92);
}

.call-media-status--failed {
  color: rgba(254, 202, 202, .94);
}

.call-actions {
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 10px;
}

.call-screen--active .call-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.call-screen--active .call-actions .icon-button,
.call-screen--active .call-actions .btn {
  width: 64px;
  height: 64px;
  border-radius: 999px;
}

.call-diagnostics {
  position: relative;
  z-index: 2;
  width: min(100%, 420px);
  justify-self: center;
  max-height: min(34dvh, 300px);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 18px;
  background: rgba(15, 23, 42, .72);
  color: rgba(255, 255, 255, .92);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .22);
  backdrop-filter: blur(16px);
}

.call-diagnostics summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 820;
  list-style: none;
}

.call-diagnostics summary::-webkit-details-marker {
  display: none;
}

.call-diagnostics summary small {
  min-width: 0;
  color: rgba(255, 255, 255, .66);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-diagnostics__body {
  display: grid;
  gap: 9px;
  padding: 0 10px 10px;
}

.call-diagnostics__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.call-diagnostics__grid span {
  min-width: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, .08);
  padding: 7px 8px;
}

.call-diagnostics__grid strong,
.call-diagnostics__grid small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-diagnostics__grid strong {
  color: rgba(255, 255, 255, .96);
  font-size: 11px;
}

.call-diagnostics__grid small {
  margin-top: 2px;
  color: rgba(255, 255, 255, .68);
  font-size: 10px;
}

.call-diagnostics .btn {
  min-height: 36px;
  border-radius: 12px;
  gap: 8px;
}

.call-diagnostics .btn svg {
  width: 15px;
  height: 15px;
}

.call-diagnostics pre {
  max-height: 128px;
  overflow: auto;
  margin: 0;
  border-radius: 12px;
  background: rgba(2, 6, 23, .78);
  color: rgba(226, 232, 240, .95);
  padding: 9px;
  font-size: 10px;
  line-height: 1.45;
  text-align: left;
  white-space: pre-wrap;
}

@media (max-height: 760px) {
  .call-screen {
    padding-bottom: calc(12px + var(--safe-bottom));
  }

  .call-main {
    gap: 7px;
    padding-block: 4px 8px;
  }

  .call-history-row {
    grid-template-columns: 44px minmax(0, 1fr);
    grid-template-areas:
      "icon main"
      "icon side";
    align-items: center;
    gap: 6px 12px;
  }

  .call-history-side {
    display: grid;
    justify-items: start;
    align-content: center;
    gap: 8px;
    min-width: 0;
  }

  .call-history-side .pill,
  .pill {
    justify-self: start;
  }

  .call-history-side small {
    max-width: 100%;
    text-align: left;
  }

  .call-video-preview {
    width: min(68%, 250px);
    height: min(30dvh, 240px);
    min-height: 120px;
  }

  .toast-stack {
    left: 16px;
    right: 16px;
    bottom: calc(88px + var(--safe-bottom));
    width: auto;
  }
}

@media (max-width: 760px) {
  .phone-shell {
    width: 100vw;
    height: 100dvh;
    padding: 0;
  }

  .phone-screen {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }

  .profile-card--compact {
    grid-template-columns: 58px minmax(0, 1fr);
    place-items: center start;
    text-align: left;
  }

  .profile-card--compact .avatar {
    grid-row: 1 / span 3;
  }

  .call-history-row {
    grid-template-columns: 44px minmax(0, 1fr);
    grid-template-areas:
      "icon main"
      "icon side";
    gap: 6px 10px;
    min-height: 74px;
    padding: 12px;
  }

  .call-history-side {
    justify-items: start;
    min-width: 0;
  }

  .call-history-side .pill,
  .pill {
    justify-self: start;
  }

  .call-history-side small {
    max-width: 100%;
    text-align: left;
  }

  .toast-stack {
    left: 16px;
    right: 16px;
    bottom: calc(88px + var(--safe-bottom));
    width: auto;
  }
}
