/* Phone layout; wide screens keep the existing two-column client. */
@media (max-width: 760px), (max-width: 1000px) and (max-height: 500px) {
  html {
    -webkit-text-size-adjust: 100%;
  }
  body {
    min-width: 0;
  }
  input,
  textarea,
  select {
    font-size: 16px;
  }
  button,
  .ghost,
  .icon-button,
  summary.icon-button {
    min-height: 44px;
  }
  .icon-button,
  summary.icon-button {
    width: 44px;
    flex-shrink: 0;
  }
  .topbar {
    height: calc(56px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0
      max(12px, env(safe-area-inset-left));
    gap: 8px;
    flex-shrink: 0;
  }
  .brand {
    font-size: 17px;
    gap: 7px;
    white-space: nowrap;
  }
  .brand-icon {
    width: 30px;
    height: 30px;
    line-height: 30px;
    font-size: 26px;
  }
  .brand-note,
  .top-actions > #connection-status {
    display: none;
  }
  .top-actions {
    gap: 4px;
    min-width: 0;
  }
  .top-actions .ghost {
    display: inline-flex;
    align-items: center;
    padding: 8px;
    font-size: 12px;
  }
  .login-layout {
    display: flex;
    flex-direction: column;
    gap: 18px;
    max-width: 440px;
    margin: 0 auto;
    padding: 22px 16px max(24px, env(safe-area-inset-bottom));
  }
  .intro {
    padding: 0 4px;
  }
  .intro h1 {
    font-size: 36px;
    line-height: 1.08;
    letter-spacing: -1.5px;
  }
  .intro h1 br {
    display: none;
  }
  .intro .eyebrow {
    font-size: 9px;
    letter-spacing: 1px;
    margin-bottom: 10px;
  }
  .intro .lead {
    font-size: 13px;
    margin-top: 10px;
  }
  .intro-art,
  .intro-footer,
  .mini-logo {
    display: none;
  }
  .login-card {
    padding: 22px;
    border-radius: 20px;
    min-width: 0;
  }
  .login-card h2 {
    font-size: 23px;
  }
  .login-card label {
    margin: 16px 0;
  }
  .login-card .primary {
    margin-top: 20px;
    min-height: 48px;
  }
  .login-note {
    margin-top: 16px;
  }
  .login-note .ghost {
    width: 100%;
    font-size: 14px;
  }

  body.client-active {
    position: fixed;
    top: var(--mobile-viewport-top, 0px);
    left: 0;
    right: 0;
    height: var(--mobile-viewport-height, 100dvh);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  body.client-active > main {
    flex: 1;
    min-height: 0;
    display: flex;
  }
  .client-layout {
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    display: flex;
    box-shadow: none;
  }
  .sidebar {
    width: 100%;
    border: 0;
    min-width: 0;
  }
  .chat-panel {
    display: none;
    width: 100%;
    min-width: 0;
  }
  .client-layout.conversation .sidebar {
    display: none;
  }
  .client-layout.conversation .chat-panel {
    display: flex;
  }
  body.client-active:has(.client-layout.conversation) > .topbar {
    display: none;
  }
  .mobile {
    display: grid;
  }
  .self {
    padding: 12px 16px;
    gap: 12px;
    flex-shrink: 0;
  }
  .self strong {
    white-space: nowrap;
    font-size: 15px;
  }
  .self select {
    font-size: 16px;
    max-width: 100%;
    min-height: 32px;
    padding: 4px 0;
  }
  .sidebar-heading {
    padding: 10px 16px 6px;
    flex-shrink: 0;
  }
  .sidebar-heading h2 {
    font-size: 21px;
  }
  .search {
    width: calc(100% - 32px);
    margin: 0 16px;
    font-size: 16px;
    min-height: 44px;
    flex-shrink: 0;
  }
  .tabs {
    margin: 8px 16px 6px;
    gap: 0;
    flex-shrink: 0;
  }
  .tabs button {
    font-size: 14px;
  }
  .social-tools {
    padding: 0 16px 8px;
    flex-shrink: 0;
  }
  .social-tools button {
    font-size: 13px;
  }
  .contact-list {
    padding: 4px 8px;
    min-height: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .contact {
    padding: 12px;
    min-height: 76px;
  }
  .contact-name {
    font-size: 15px;
  }
  .contact-meta {
    font-size: 12px;
  }
  .sidebar-footer {
    padding: 6px 16px max(8px, env(safe-area-inset-bottom));
    flex-shrink: 0;
  }
  .sidebar-footer button {
    font-size: 12px;
  }
  .room-add {
    min-height: 44px;
    flex-shrink: 0;
  }

  .chat-header {
    padding: max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right)) 8px
      max(8px, env(safe-area-inset-left));
    min-height: 64px;
    gap: 6px;
    flex-shrink: 0;
  }
  .chat-header .avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }
  .chat-heading h2 {
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .chat-heading p {
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 3px;
  }
  .chat-heading {
    min-width: 0;
  }
  .menu {
    min-width: 220px;
    max-width: calc(100vw - 16px);
  }
  .menu button {
    font-size: 14px;
  }
  .message-search {
    padding: 6px 12px;
    gap: 8px;
    flex-shrink: 0;
  }
  .message-search input {
    font-size: 16px;
    min-width: 0;
    padding: 8px 10px;
  }
  .message-search span {
    flex-shrink: 0;
  }
  .messages {
    padding: 12px;
    min-height: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .bubble {
    max-width: 90%;
    min-width: 0;
    padding: 10px 12px;
  }
  .message-body {
    font-size: 15px;
    line-height: 1.5;
  }
  .message-meta {
    font-size: 11px;
  }
  .typing {
    min-height: 20px;
    padding: 2px 14px;
    flex-shrink: 0;
  }
  .room-members {
    padding: 6px 14px;
    max-height: 60px;
    overflow-y: auto;
    flex-shrink: 0;
  }
  .composer {
    padding: 6px max(8px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    gap: 4px;
    flex-shrink: 0;
    background: var(--panel);
    border-top: 1px solid var(--line);
  }
  .composer textarea {
    font-size: 16px;
    line-height: 1.4;
    padding: 12px 10px;
    min-height: 46px;
    max-height: min(160px, 24dvh);
  }
  .composer .icon-button {
    width: 44px;
    min-height: 46px;
    padding: 0;
  }
  .composer .primary {
    font-size: 0;
    width: 44px;
    height: 46px;
    padding: 0;
    gap: 0;
    justify-content: center;
    border-radius: 14px;
    background: var(--green);
    color: var(--panel);
  }
  .composer .primary span {
    font-size: 24px;
  }
  .composer-note {
    display: none;
  }
  .attachment-drafts {
    padding: 6px 12px;
    max-height: 88px;
    overflow-y: auto;
    flex-shrink: 0;
  }
  .attachment-card {
    max-width: 100%;
  }
  .upload-progress {
    flex-shrink: 0;
  }

  dialog,
  .wide-dialog,
  #profile-dialog {
    position: fixed;
    top: calc(var(--mobile-viewport-top, 0px) + 12px);
    bottom: auto;
    left: 8px;
    right: 8px;
    width: min(520px, calc(100% - 16px));
    margin: 0 auto;
    padding: 20px;
    max-height: calc(var(--mobile-viewport-height, 100dvh) - 24px);
    border-radius: 20px;
    overscroll-behavior: contain;
    overflow-x: hidden;
  }
  .dialog-header h2 {
    font-size: 20px;
    min-width: 0;
  }
  .dialog-header .close {
    flex-shrink: 0;
  }
  dialog label {
    margin: 16px 0;
  }
  dialog .primary {
    min-height: 48px;
  }
  .profile-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }
  .profile-avatar-row {
    flex-wrap: wrap;
  }
  .profile-avatar-row button {
    font-size: 12px;
  }
  .directory-form {
    grid-template-columns: minmax(0, 1fr) 100px;
  }
  .directory-form select {
    min-width: 0;
  }
  .directory-form .primary {
    grid-column: 1 / -1;
  }
  .directory-result {
    flex-wrap: wrap;
    gap: 10px;
  }
  .directory-actions {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .directory-actions .primary {
    width: auto;
  }
  .request-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .request-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .request-actions .primary {
    width: auto;
  }
  .smile-grid {
    gap: 8px;
  }
  .smile-choice {
    min-height: 58px;
    padding: 8px;
  }
  .uin-card {
    font-size: clamp(23px, 7vw, 36px);
    letter-spacing: 1px;
    padding: 16px;
    overflow-wrap: anywhere;
  }
  .toast {
    bottom: max(16px, env(safe-area-inset-bottom));
    width: max-content;
    overflow-wrap: anywhere;
  }
}
@media (max-width: 1000px) and (max-height: 500px) {
  .self {
    padding: 6px 12px;
  }
  .self .avatar {
    width: 34px;
    height: 34px;
  }
  .self select {
    min-height: 26px;
  }
  .sidebar-heading {
    padding: 2px 12px;
  }
  .sidebar-heading h2 {
    font-size: 17px;
  }
  .social-tools {
    padding-bottom: 0;
  }
  .tabs {
    margin-top: 2px;
    margin-bottom: 2px;
  }
  .tabs button {
    padding: 6px 2px;
  }
  .sidebar-footer {
    padding-top: 0;
    padding-bottom: max(2px, env(safe-area-inset-bottom));
  }
  .chat-header {
    min-height: 56px;
    padding-top: max(4px, env(safe-area-inset-top));
    padding-bottom: 4px;
  }
  .message-search {
    padding-top: 2px;
    padding-bottom: 2px;
  }
  .typing:empty {
    display: none;
  }
}

@media (max-width: 760px), (max-width: 1000px) and (max-height: 500px) {
  a.ghost {
    color: inherit;
  }
}
