/* Mobil WhatsApp tarzı düzen */
.mobile-only { display: none !important; }
.desktop-only { display: initial; }

@media (max-width: 1024px) {
  .mobile-only { display: flex !important; }
  .desktop-only,
  .desktop-room-title,
  .chat-header-desc { display: none !important; }

  .auth-card {
    padding: 24px 20px;
    max-width: 100%;
  }

  html,
  body.layout-mobile,
  html.layout-compact {
    overflow: hidden;
    max-width: 100vw;
    height: 100%;
    height: 100dvh;
  }

  body.layout-mobile:not(.auth-screen-active),
  html.layout-compact body:not(.auth-screen-active) {
    position: fixed;
    inset: 0;
    width: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  html.layout-compact.auth-screen-active,
  body.layout-mobile.auth-screen-active {
    position: static;
    inset: auto;
    width: 100%;
    max-width: 100vw;
    height: auto;
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .chat-app.active {
    grid-template-columns: 1fr !important;
    grid-template-rows: 1fr !important;
    height: 100dvh;
    max-height: 100dvh;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
    box-sizing: border-box;
  }

  .chat-app.active > .sidebar,
  .chat-app.active > .chat-area,
  .chat-app.active > .right-panel {
    grid-row: 1;
    grid-column: 1;
    min-height: 0;
  }

  .chat-area {
    width: 100%;
    max-width: 100vw;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    position: relative;
    min-height: 0;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
  }

  html.layout-compact #chatHeader {
    display: flex !important;
  }

  html.layout-compact body:not(.mobile-in-room) #btnMobileBack,
  html.layout-compact body:not(.mobile-in-room) #btnMobileMembers {
    visibility: hidden;
    pointer-events: none;
    width: 0;
    min-width: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
  }

  /* Odadayken üst bar ikonları — hızlı menü (chat-rail) yeterli */
  html.layout-compact body.mobile-in-room .chat-header-actions > .mobile-header-btn,
  html.layout-compact body.mobile-in-room #btnRoomOwnerSettings {
    display: none !important;
  }

  html.layout-compact body:not(.mobile-in-room) #mobileRoomHash {
    display: block !important;
  }

  .sidebar {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(88vw, 320px);
    z-index: 1200;
    transform: translateX(-105%);
    transition: transform 0.28s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  .mobile-drawer-close,
  .mobile-panel-close {
    display: none;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: max(10px, env(safe-area-inset-top, 0px));
    z-index: 60;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 50%;
    background: var(--bg-white, #fff);
    color: #3b4a54;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  }

  .mobile-close-glyph {
    display: block;
    font-size: 22px;
    line-height: 1;
    font-weight: 400;
    color: inherit;
    pointer-events: none;
    user-select: none;
    margin-top: -1px;
  }

  .mobile-drawer-close {
    right: 10px;
  }

  .mobile-panel-close {
    right: 10px;
    left: auto;
  }

  .mobile-drawer-close:active,
  .mobile-panel-close:active {
    background: #eef0f2;
    transform: scale(0.96);
  }

  html.layout-compact .mobile-drawer-close,
  html.layout-compact .mobile-panel-close {
    display: flex;
  }

  html.layout-compact .sidebar-user-header {
    padding-right: 44px;
  }

  html.layout-compact .right-panel {
    flex-direction: column;
  }

  html.layout-compact #rightPanelContent {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    position: relative;
    z-index: 1;
  }

  html.layout-compact .right-panel-header {
    padding-right: 48px;
    min-height: 48px;
    box-sizing: border-box;
  }

  .sidebar.mobile-drawer-open {
    transform: translateX(0);
  }

  .chat-live-shell {
    overflow: hidden;
  }

  .chat-header {
    flex: 0 0 auto;
    flex-shrink: 0;
    position: relative;
    top: auto;
    margin: 0;
    padding: max(8px, env(safe-area-inset-top, 0px)) 10px 8px;
    min-height: 52px;
    box-sizing: border-box;
    background: #f0f2f5;
    border-bottom: 1px solid #d1d7db;
    gap: 8px;
    z-index: 5;
  }

  .chat-header-info .chat-header-desc {
    display: none !important;
  }

  .chat-header-info h3 {
    margin: 0;
    line-height: 1.25;
  }

  .mobile-header-btn {
    border: none;
    background: transparent;
    font-size: 20px;
    padding: 6px 8px;
    color: #54656f;
    position: relative;
    align-items: center;
    justify-content: center;
  }

  .header-badge {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 10px;
    font-weight: 700;
    background: #25d366;
    color: #fff;
    border-radius: 8px;
    line-height: 16px;
    text-align: center;
  }

  .mobile-room-hash {
    font-size: 16px;
    font-weight: 600;
    color: #111b21;
    margin: 0;
  }

  .chat-header-avatar {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .chat-live-shell {
    flex: 1;
    min-height: 0;
  }

  .messages-container {
    padding: 8px 10px 72px;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    background-color: #e5ddd5;
    background-image: url("data:image/svg+xml,%3Csvg width='80' height='80' viewBox='0 0 80 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23c8c0b8' fill-opacity='0.45'%3E%3Cpath d='M0 0h40v40H0V0zm40 40h40v40H40V40z'/%3E%3C/g%3E%3C/svg%3E");
  }

  .message {
    max-width: 88%;
    margin-bottom: 4px;
  }

  .message-bubble {
    background: #fff;
    border: 1px solid #e9edef;
    border-radius: 8px;
    box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
    padding: 6px 10px 4px;
  }

  .message.own .message-bubble {
    background: #d9fdd3;
    border-color: #d1e8cc;
  }

  .message-profile {
    width: 40px;
  }

  .message-avatar-wrap {
    width: 36px;
    height: 36px;
    font-size: 13px;
  }

  .message-sender {
    font-size: 9px;
    max-width: 44px;
  }

  #messagesContainer .message-bubble-content .message-sender-line,
  #pmMessagesContainer .message-bubble-content .message-sender-line {
    font-size: 12px;
    margin-bottom: 3px;
  }

  #messagesContainer .message-bubble-content .nick-display-image,
  #pmMessagesContainer .message-bubble-content .nick-display-image {
    max-height: 18px;
    max-width: min(140px, 100%);
  }

  /* Mobilde resimli nick: bazı yüzeylerde çok büyümeyi engelle */
  .sidebar-user-header .nick-display-image {
    max-height: 16px;
    max-width: min(160px, 100%);
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: left center;
  }

  .typing-bubble-name .nick-display-image:not([style*='max-height']),
  .member-name .nick-display-image:not([style*='max-height']),
  .online-user-name .nick-display-image:not([style*='max-height']),
  .chat-list-name .nick-display-image:not([style*='max-height']),
  .voice-tile-name .nick-display-image:not([style*='max-height']),
  .voice-queue-name .nick-display-image:not([style*='max-height']),
  .gift-ticker-sender .nick-display-image:not([style*='max-height']),
  .gift-ticker-recipient .nick-display-image:not([style*='max-height']),
  #pmPanelTitle .nick-display-image:not([style*='max-height']),
  .pm-panel-peer-name .nick-display-image:not([style*='max-height']) {
    max-height: 22px;
    max-width: min(140px, 100%);
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: left center;
    display: inline-block;
    vertical-align: middle;
  }

  .pm-messages-container .message-profile {
    width: 40px;
  }

  .pm-messages-container .message-avatar-wrap {
    width: 36px;
    height: 36px;
    font-size: 13px;
  }

  .chat-input-area {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 6px max(8px, env(safe-area-inset-left, 0px)) calc(8px + env(safe-area-inset-bottom, 0))
      max(8px, env(safe-area-inset-right, 0px));
  }

  html.layout-compact .chat-live-shell {
    padding-right: 0 !important;
  }

  html.layout-compact .chat-input-area {
    width: 100% !important;
    max-width: 100% !important;
    padding-right: max(8px, env(safe-area-inset-right, 0px)) !important;
    padding-left: max(8px, env(safe-area-inset-left, 0px)) !important;
  }

  html.layout-compact .chat-rail {
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    top: auto;
    transform: none;
  }

  .typing-bubbles-wrap {
    position: absolute;
    left: 8px;
    right: 56px;
    bottom: 6px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    padding: 0;
  }

  .typing-bubble {
    background: rgba(255, 255, 255, 0.92);
    color: #3b4a54;
    border-radius: 14px;
    padding: 4px 8px 4px 4px;
    font-size: 11px;
    border: 1px solid #e9edef;
    max-width: min(72vw, 200px);
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }

  .typing-bubble-avatar {
    display: flex;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
  }

  .typing-bubble-body {
    flex-direction: row;
    align-items: center;
    gap: 6px;
  }

  .typing-bubble-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100px;
    font-size: 12px;
    font-weight: 600;
    color: #111b21;
  }

  .chat-live-shell .typing-bubble .typing-bubble-name {
    color: #ffffff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }

  .typing-dots {
    display: inline-flex;
    flex-shrink: 0;
  }

  .voice-note-bar {
    margin-bottom: 0;
  }

  .msg-attachment-audio {
    min-width: 200px;
  }

  .msg-attachment-audio audio {
    width: 100%;
    max-width: 260px;
    height: 36px;
  }

  /* Modallar çekmece (1200) ve üye paneli (1300) üstünde */
  .context-menu {
    z-index: calc(var(--z-ui-overlay, 25000) + 50);
  }

  .mobile-header-btn {
    position: relative;
  }

  .mobile-header-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--danger);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }

  .mobile-header-badge.hidden {
    display: none !important;
  }

  .mobile-drawer-backdrop,
  .mobile-sheet-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1100;
  }

  .mobile-drawer-backdrop.open,
  .mobile-sheet-backdrop.open {
    display: block;
  }

  .right-panel {
    display: flex !important;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(88vw, 300px);
    z-index: 1300;
    transform: translateX(105%);
    transition: transform 0.28s ease;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
    border-left: 1px solid var(--border);
  }

  .right-panel.mobile-panel-open {
    transform: translateX(0);
  }

  .voice-stage-wrap {
    max-height: none;
  }

  .voice-stage-scroll {
    max-height: min(44vh, 360px);
    gap: 4px;
    padding: 2px 4px 6px;
    justify-content: flex-start;
  }

  .chat-live-shell.has-live-voice .voice-stage-scroll {
    max-height: min(48vh, 380px);
    gap: 4px;
  }

  html.layout-compact .voice-stage-scroll .voice-tile {
    flex: 0 0 calc((100% - 12px) / 4);
    width: calc((100% - 12px) / 4);
    max-width: 82px;
    min-height: 72px;
  }

  html.layout-compact .chat-live-shell.has-live-voice .voice-stage-scroll .voice-tile {
    flex: 0 0 calc((100% - 12px) / 4);
    width: calc((100% - 12px) / 4);
    max-width: 80px;
    min-height: 78px;
  }

  html.layout-compact .voice-stage-scroll .voice-tile-media,
  html.layout-compact .chat-live-shell.has-live-voice .voice-stage-scroll .voice-tile-media {
    width: 100%;
    max-width: 68px;
    height: auto;
    aspect-ratio: 1;
    margin: 0 auto;
  }

  html.layout-compact .voice-stage-scroll .voice-tile .voice-tile-name,
  html.layout-compact .chat-live-shell.has-live-voice .voice-stage-scroll .voice-tile .voice-tile-name {
    max-width: 100%;
    font-size: 9px;
  }

  html.layout-compact .chat-live-shell.has-live-voice .messages-container {
    display: block;
    overflow-y: scroll;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
  }

  html.layout-compact .chat-live-shell.has-live-voice .messages-container::before {
    display: block;
    flex: none;
    height: min(42vh, 300px);
    min-height: 120px;
    content: '';
    pointer-events: none;
  }

  html.layout-compact .voice-stage-wrap {
    max-height: min(46vh, 320px);
    pointer-events: none;
  }

  html.layout-compact .voice-stage-wrap .voice-stage-scroll,
  html.layout-compact .voice-stage-wrap .voice-tile,
  html.layout-compact .voice-stage-wrap button {
    pointer-events: auto;
  }

  .scroll-bottom-btn {
    right: 56px;
    bottom: 8px;
  }

  body.theme-dark .mobile-drawer-close,
  body.theme-dark .mobile-panel-close {
    background: #2a3942;
    border-color: rgba(255, 255, 255, 0.14);
    color: #e9edef;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  }

  body.theme-dark .mobile-drawer-close:active,
  body.theme-dark .mobile-panel-close:active {
    background: #374248;
  }
}
