/* ===== MOBILE RESPONSIVE (≤ 768px) ===== */

/* ── Always hidden on desktop, shown inside media query ──────────────────────*/
#mobile-menu-btn { display: none; }
#dm-back-btn     { display: none; }

@media (max-width: 768px) {

  /* ── Hamburger button — hidden on desktop ──────────────────────────────────*/
  #mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    color: var(--ink3);
    font-size: 20px;
    cursor: pointer;
    border-radius: 7px;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
    margin-right: 4px;
  }
  #mobile-menu-btn:hover { background: var(--paper2); color: var(--ink); }

  /* ── Mobile sidebar overlay (tap to close) ─────────────────────────────────*/
  #mobile-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 498;
  }
  #mobile-sidebar-overlay.visible { display: block; }

  /* ── Server rail — hide, show inside drawer instead ───────────────────────*/
  .server-rail {
    display: none;
  }

  /* ── Sidebar — becomes a slide-in drawer ───────────────────────────────────*/
  #main-sidebar {
    position: fixed !important;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(var(--sidebar-w), 85vw) !important;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    z-index: 499;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }
  #main-sidebar.mobile-open {
    transform: translateX(0);
  }

  /* ── Bottom panel — span full width ───────────────────────────────────────*/
  #app-bottom-panel {
    width: 100% !important;
    left: 0 !important;
    border-right: none;
  }

  /* ── Right panel — hidden by default, shown as overlay over message area ────*/
  #pane-primary {
    position: relative;
  }
  .right-panel {
    display: none !important;
    position: absolute !important;
    top: 52px !important;  /* below channel title bar */
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    z-index: 400;
    border-left: none !important;
  }
  .right-panel.mobile-open {
    display: flex !important;
  }

  /* ── Split view — suppress entirely ───────────────────────────────────────*/
  #secondary-pane,
  #split-view-container > #secondary-pane,
  .split-view-divider,
  #split-toggle-btn,
  #split-close-primary {
    display: none !important;
  }

  /* ── App shell — use dynamic viewport height + clear fixed bottom panel ─────*/
  #app-shell {
    overflow: hidden;
    height: 100dvh !important;
    padding-bottom: 54px;
  }

  /* Main content area fills full width ─────────────────────────────────────*/
  #primary-pane,
  .content-pane {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* ── Channel bar ───────────────────────────────────────────────────────────*/
  .channel-bar-top {
    padding: 8px 10px;
  }
  .channel-title {
    font-size: 14px;
  }
  .channel-topic {
    display: none;
  }
  /* DM view uses position:absolute;bottom:0 ────────────────────────────────*/
  #dm-view {
    bottom: 54px !important;
  }

  /* ── Messages scroll area ──────────────────────────────────────────────────*/
  .messages {
    padding: 12px 12px 8px;
  }
  #dm-messages {
    padding-bottom: 8px;
  }
  /* Input area ───────────────────────────────────────────────────────────────*/
  .input-area {
    padding: 8px 10px 12px;
  }

  /* ── Modals — full-width on small screens ──────────────────────────────────*/
  .modal-box {
    width: 96vw !important;
    max-width: 96vw !important;
    max-height: 92vh !important;
    margin: 0 auto;
  }

  /* ── Gem Settings on mobile — bottom-sheet + slide-in page ───────────────*/
  /* Hide the desktop tabbed modal entirely on mobile */
  #group-settings-overlay { display: none !important; }

  /* Hide the bottom app panel while mobile gem settings are open */
  body.gs-mobile-open #app-bottom-panel { display: none !important; }

  /* ── Sheet (slides DOWN from top, leaves a peek of channel list at bottom) */
  #gs-mobile-sheet {
    position: fixed;
    inset: 0;
    z-index: 600;
    pointer-events: none;
  }
  #gs-mobile-sheet.visible { pointer-events: auto; }
  #gs-mobile-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    transition: opacity 0.22s ease;
  }
  #gs-mobile-sheet.visible #gs-mobile-sheet-backdrop { opacity: 1; }
  #gs-mobile-sheet-panel {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 60px; /* peek of channel list at bottom — tap to dismiss */
    background: var(--paper);
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 14px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    transform: translateY(-105%);
    transition: transform 0.26s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  #gs-mobile-sheet.visible #gs-mobile-sheet-panel {
    transform: translateY(0);
  }
  #gs-mobile-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--rule);
    flex-shrink: 0;
    font-weight: 700;
    font-size: 16px;
    color: var(--ink);
  }
  #gs-mobile-sheet-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
  }
  .gs-mobile-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    cursor: pointer;
    border-bottom: 1px solid var(--rule);
    color: var(--ink);
    font-size: 15px;
    background: transparent;
    border-left: none;
    border-right: none;
    border-top: none;
    width: 100%;
    text-align: left;
  }
  .gs-mobile-row:active { background: var(--paper2); }
  .gs-mobile-row .gs-mobile-row-label { flex: 1; min-width: 0; }
  .gs-mobile-row .gs-mobile-row-chevron { color: var(--ink3); font-size: 18px; flex-shrink: 0; }
  .gs-mobile-row.danger { color: var(--red); }

  /* ── Page (slides IN from left, originating from sheet's tab list) ───────*/
  #gs-mobile-page {
    position: fixed;
    inset: 0;
    z-index: 700;
    background: var(--paper);
    transform: translateX(-100%);
    transition: transform 0.26s ease;
    display: flex;
    flex-direction: column;
  }
  #gs-mobile-page.visible { transform: translateX(0); }
  #gs-mobile-page-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--rule);
    flex-shrink: 0;
    background: var(--paper);
  }
  #gs-mobile-page-back {
    background: none;
    border: none;
    color: var(--ink);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 10px;
    line-height: 1;
  }
  #gs-mobile-page-title {
    font-weight: 700;
    font-size: 16px;
    color: var(--ink);
  }
  #gs-mobile-page-body {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
  }
  /* When a panel is hosted inside the mobile page, neutralize its desktop
     panel sizing so it fills the page body naturally */
  #gs-mobile-page-body .modal-body {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
  }

  /* User settings modal ─────────────────────────────────────────────────────*/
  .settings-panel {
    width: 96vw !important;
    max-width: 96vw !important;
    height: 92vh !important;
  }
  .settings-nav {
    width: 110px !important;
  }

  /* Friends modal ───────────────────────────────────────────────────────────*/
  .friends-modal {
    width: 96vw !important;
    max-width: 96vw !important;
  }

  /* ── Voice control buttons — tighter on mobile ─────────────────────────────*/
  .vc-btn {
    height: 46px !important;
    min-height: 46px !important;
    max-height: 46px !important;
  }
  .vc-btn .vcl { display: none; } /* hide labels, icons only */

  /* ── Profile card — full width ─────────────────────────────────────────────*/
  .profile-card {
    width: min(260px, 90vw) !important;
  }

  /* ── Context menus — full-width bottom sheet feel ──────────────────────────*/
  .ctx-menu {
    min-width: 200px !important;
  }

  /* ── DM overlay ────────────────────────────────────────────────────────────*/
  #dm-overlay {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ── Bottom safe area for iOS home bar ─────────────────────────────────────*/
  #app-bottom-panel {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  /* ── Gem bar — icon only on mobile ────────────────────────────────────────*/
  /* Hide text/status from gem tabs and social tab */
  .gt-name,
  .gt-status,
  .gt-quiet,
  .gt-stat,
  .gt-stat-sep { display: none !important; }

  /* Tighten tab padding since no text */
  .group-tab {
    min-width: 40px !important;
    max-width: 52px !important;
    padding: 4px 6px !important;
  }
  .group-tab.gt-dm {
    min-width: 40px !important;
    max-width: 52px !important;
  }

  /* Hide ⠿ reorder button — drag doesn't work on touch */
  #gt-edit-btn { display: none !important; }

  /* Hide pinned messages tab */
  #pins-tab-anchor { display: none !important; }

  /* Hide grabby on mobile ─────────────────────────────────────────────────────*/
  .grabby-btn, .grabby-standalone { display: none !important; }

  /* ── Voice panel — collapsible on mobile ───────────────────────────────────*/
  #vc-panel-toggle {
    display: flex !important;
  }
  #vc-collapsible {
    overflow: hidden;
    max-height: 0;
    padding: 0 !important;
    border-top: none !important;
    transition: max-height 0.25s ease, padding 0.25s ease;
  }
  #vc-collapsible.expanded {
    max-height: 200px;
    padding: 8px 10px !important;
    border-top: 1px solid var(--sidebar-border) !important;
  }
  /* Rotate chevron when expanded */
  #vc-panel-toggle.expanded { transform: rotate(180deg); }

  /* Adjust app-shell and dm-view bottom clearance for expanded panel ─────────*/
  #app-shell.vc-panel-expanded {
    padding-bottom: 200px;
  }
  #dm-view.vc-panel-expanded {
    bottom: 200px !important;
  }
  /* Sidebar takes full width, message area hidden until a DM is opened */
  .dm-sidebar {
    width: 100% !important;
    flex-shrink: 0;
  }
  .dm-main {
    display: none !important;
    width: 100% !important;
    position: absolute !important;
    inset: 0 !important;
    z-index: 10;
    background: var(--paper);
  }
  .dm-main.mobile-open {
    display: flex !important;
  }
  #dm-back-btn {
    display: flex !important;
  }
}
