/**
 * Community page — mobile layout (max-width 767px).
 * Desktop styles remain in index.html inline <style>.
 */

/* Chat head buttons — ID selectors (survive cached HTML/class drift) */
#chatCard .chat-head-actions #chatMiniAppsBtn,
#chatCard .chat-head-actions #chatRulesBtn,
#chatCard .chat-head-actions #btnProfileChat,
#chatCard .chat-head-actions #chatPopoutBtn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: auto;
  width: auto;
  height: auto;
  padding: 6px 15px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.2;
  box-sizing: border-box;
  flex-shrink: 0;
}

#chatCard .chat-head-actions #chatMiniAppsBtn {
  border: 1px solid rgba(139, 92, 246, 0.48) !important;
  background: linear-gradient(165deg, rgba(139, 92, 246, 0.16), rgba(11, 27, 38, 0.72)) !important;
  color: #d4c4ff !important;
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.12), 0 0 16px rgba(139, 92, 246, 0.14);
}

#chatCard .chat-head-actions #chatRulesBtn {
  border: 1px solid rgba(212, 175, 55, 0.55) !important;
  background: linear-gradient(165deg, rgba(245, 197, 66, 0.14), rgba(11, 27, 38, 0.72)) !important;
  color: #f5d08a !important;
  box-shadow: 0 0 0 1px rgba(212, 175, 55, 0.12), 0 0 14px rgba(245, 197, 66, 0.12);
}

#chatCard .chat-head-actions #btnProfileChat {
  border: 1px solid rgba(77, 163, 255, 0.45) !important;
  background: linear-gradient(165deg, rgba(77, 163, 255, 0.16), rgba(11, 27, 38, 0.72)) !important;
  color: #9bcbff !important;
  box-shadow: 0 0 0 1px rgba(77, 163, 255, 0.1), 0 0 16px rgba(77, 163, 255, 0.12);
}

#chatCard .chat-head-actions #chatPopoutBtn {
  min-width: 32px;
  padding: 6px 10px;
  border: 1px solid rgba(87, 183, 164, 0.45) !important;
  background: linear-gradient(165deg, rgba(87, 183, 164, 0.12), rgba(11, 27, 38, 0.72)) !important;
  color: #9ef0c8 !important;
  box-shadow: 0 0 0 1px rgba(87, 183, 164, 0.1), 0 0 14px rgba(87, 183, 164, 0.1);
}

#chatCard .chat-head-actions #chatRulesBtn .tb-link--rules__icon,
#chatCard .chat-head-actions #chatRulesBtn .chat-rules-btn__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(212, 175, 55, 0.4);
  padding: 2px;
  flex-shrink: 0;
}

#chatCard .chat-head-actions #chatRulesBtn .tb-link--rules__icon svg,
#chatCard .chat-head-actions #chatRulesBtn .chat-rules-btn__icon {
  width: 13px;
  height: 13px;
  display: block;
}

#chatCard .chat-head-actions .mini-apps-menu {
  z-index: 50000;
}

#chatCard .chat-head-actions .mini-apps-menu.is-open.is-fixed {
  position: fixed;
  z-index: 50001;
}

/* Desktop default: mobile-only UI must not appear in document flow */
.mobile-bottom-nav,
.mobile-menu-drawer {
  display: none !important;
}

@media (max-width: 767px) {
  html,
  body {
    height: 100%;
    min-height: 100dvh;
  }

  body.sa-mobile-layout {
    overflow: hidden;
  }

  body.sa-mobile-layout .app {
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
  }

  /* Topbar compact */
  body.sa-mobile-layout .topbar {
    height: auto;
    min-height: 52px;
    padding: 8px 10px;
    flex-wrap: wrap;
    gap: 6px;
  }

  body.sa-mobile-layout .topbar-brand {
    flex: 1 1 auto;
    min-width: 0;
  }

  body.sa-mobile-layout .topbar-logo {
    font-size: 17px;
    line-height: 1.2;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(52vw, 220px);
  }

  body.sa-mobile-layout .topbar-motto {
    display: none;
  }

  body.sa-mobile-layout .tb-nav {
    display: none !important;
  }

  body.sa-mobile-layout .tb-right {
    margin-left: 0;
    flex-shrink: 0;
    gap: 4px;
  }

  body.sa-mobile-layout .tb-right .btn {
    padding: 8px 10px;
    min-height: 40px;
    font-size: 11px;
  }

  body.sa-mobile-layout .tb-panel-link {
    display: none !important;
  }

  /* Main stage + tabs */
  body.sa-mobile-layout .main-stage {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  body.sa-mobile-layout .content {
    padding: 8px 8px 6px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  body.sa-mobile-layout .content-layout {
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 8px;
  }

  body.sa-mobile-layout .content-main,
  body.sa-mobile-layout .content-chat-column {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    min-height: 0;
    overflow: hidden;
    display: none;
  }

  body.sa-mobile-layout[data-mobile-tab='home'] .content-main {
    display: flex;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.sa-mobile-layout[data-mobile-tab='chat'] .content-chat-column {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  body.sa-mobile-layout #chatCard.card,
  body.sa-mobile-layout #chatCard {
    overflow: visible;
  }

  /* Stream card mobile */
  body.sa-mobile-layout #streamCard {
    flex: 0 0 auto;
    min-height: 0;
  }

  body.sa-mobile-layout #streamCard .stream-card-head {
    flex-wrap: wrap;
    gap: 6px 8px;
  }

  body.sa-mobile-layout #streamCard .stream-card-head .stream-link-panel {
    flex: 1 1 100%;
    order: 3;
  }

  body.sa-mobile-layout #streamCard .stream-body {
    flex-direction: column;
    flex: none;
  }

  body.sa-mobile-layout #streamCard .stream-body .stream-frame {
    flex: none;
    aspect-ratio: 16 / 9;
    min-height: 0;
    width: 100%;
  }

  body.sa-mobile-layout #streamCard .stream-sidebar {
    flex: none;
    max-width: none;
    min-width: 0;
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: min(42vh, 320px);
  }

  body.sa-mobile-layout #streamCard.stream-sidebar-hidden .stream-sidebar {
    display: none;
  }

  body.sa-mobile-layout .stream-panel-toggle {
    min-height: 36px;
    padding: 6px 12px;
  }

  /* Chat mobile */
  body.sa-mobile-layout #chatCard {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  body.sa-mobile-layout #chatCard .chat-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  body.sa-mobile-layout #chatCard .chat-msgs {
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  body.sa-mobile-layout #chatCard .chat-foot {
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, rgba(26, 44, 56, 0.92), rgba(26, 44, 56, 0.98));
    z-index: 2;
  }

  body.sa-mobile-layout #chatPopoutBtn,
  body.sa-mobile-layout .chat-float-window,
  body.sa-mobile-layout .generic-float-window {
    display: none !important;
  }

  body.sa-mobile-layout #chatCard .chat-card-head {
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }

  body.sa-mobile-layout #chatCard .chat-card-head .card-title {
    flex: 1 1 100%;
    min-width: 0;
  }

  body.sa-mobile-layout #chatCard .chat-head-actions {
    margin-left: 0;
    width: 100%;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    overflow: visible;
    padding-bottom: 2px;
  }

  body.sa-mobile-layout #chatCard .chat-head-actions #chatMiniAppsBtn,
  body.sa-mobile-layout #chatCard .chat-head-actions #chatRulesBtn,
  body.sa-mobile-layout #chatCard .chat-head-actions #btnProfileChat,
  body.sa-mobile-layout #chatCard .chat-head-actions #chatPopoutBtn {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 11px;
  }

  body.sa-mobile-layout #chatCard .chat-head-actions .tb-link--mini-apps__icon {
    width: 16px;
    height: 16px;
    font-size: 9px;
  }

  body.sa-mobile-layout #chatCard .send-btn {
    min-width: 44px;
    min-height: 44px;
    flex-shrink: 0;
  }

  body.sa-mobile-layout #chatCard .chat-input-wrap {
    flex-wrap: nowrap;
    gap: 4px;
  }

  body.sa-mobile-layout #chatCard .char-count {
    font-size: 10px;
  }

  body.sa-mobile-layout #chatCard .chat-input-wrap input {
    min-height: 44px;
    font-size: 16px;
  }

  /* Profile + mod tools mobile */
  body.sa-mobile-layout .tips-sent-note {
    display: flex !important;
    flex-shrink: 0;
    padding: 5px 10px;
    gap: 8px;
    min-height: 28px;
    z-index: 90;
  }

  body.sa-mobile-layout .tips-sent-note__label {
    font-size: 0;
    width: 0;
    overflow: hidden;
  }

  body.sa-mobile-layout .tips-sent-note__label::before {
    content: 'Latest tips';
    font-size: 10px;
    white-space: nowrap;
    display: block;
    width: auto;
  }

  /* Bottom navigation */
  body.sa-mobile-layout .mobile-bottom-nav {
    display: flex !important;
    flex-shrink: 0;
    align-items: stretch;
    justify-content: space-around;
    gap: 4px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, rgba(20, 36, 48, 0.98), rgba(15, 33, 46, 0.98));
    border-top: 1px solid var(--border);
    z-index: 100;
  }

  body.sa-mobile-layout .mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 48px;
    padding: 6px 4px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text2);
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
  }

  body.sa-mobile-layout .mobile-nav-btn.is-active {
    background: var(--teal-dim);
    color: #8dff8f;
    border: 1px solid rgba(0, 231, 1, 0.35);
  }

  body.sa-mobile-layout .mobile-nav-btn[hidden] {
    display: none !important;
  }

  body.sa-mobile-layout .mobile-nav-btn__icon {
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border2);
    background: rgba(11, 27, 38, 0.55);
  }

  /* Menu drawer */
  body.sa-mobile-layout .mobile-menu-drawer {
    display: none !important;
    position: fixed;
    inset: 0;
    z-index: 48000;
    align-items: flex-end;
    justify-content: center;
  }

  body.sa-mobile-layout .mobile-menu-drawer.open {
    display: flex !important;
  }

  body.sa-mobile-layout .mobile-menu-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
  }

  body.sa-mobile-layout .mobile-menu-panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-height: min(72dvh, 520px);
    padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    border-radius: 16px 16px 0 0;
    background: linear-gradient(180deg, rgba(33, 55, 67, 0.98), rgba(15, 33, 46, 0.98));
    border: 1px solid var(--border2);
    border-bottom: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.sa-mobile-layout .mobile-menu-title {
    margin: 0 0 10px;
    font-size: 14px;
    font-weight: 800;
    color: var(--text);
  }

  body.sa-mobile-layout .mobile-menu-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  body.sa-mobile-layout .mobile-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(11, 27, 38, 0.55);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
  }

  body.sa-mobile-layout .mobile-menu-item:active,
  body.sa-mobile-layout .mobile-menu-item:hover {
    border-color: rgba(0, 231, 1, 0.45);
    background: rgba(0, 231, 1, 0.08);
  }

  /* Profile + mod tools mobile */
  body.sa-mobile-layout #profileModal .profile-modal-panel {
    width: min(460px, 94vw) !important;
    min-width: 0 !important;
    max-height: min(90dvh, 736px) !important;
  }

  body.sa-mobile-layout #modToolsModal .mod-tools-panel {
    position: fixed !important;
    inset: 8px !important;
    left: 8px !important;
    top: 8px !important;
    right: 8px !important;
    bottom: 8px !important;
    width: auto !important;
    height: auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: none !important;
    max-height: none !important;
    transform: none !important;
    border-radius: 12px;
  }

  body.sa-mobile-layout #modToolsModal .mod-tools-resize-handle {
    display: none;
  }

  body.sa-mobile-layout #profileModal .profile-modal-head {
    cursor: default;
  }
}
