/* ===== 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 — stack nav on top instead of left side ───────────────────*/
  #group-settings-overlay .modal-box {
    width: 96vw !important;
    height: 92vh !important;
  }
  /* Left nav becomes a horizontal scroll row */
  #group-settings-overlay [style*="width:168px"] {
    width: 100% !important;
    flex-direction: row !important;
    border-right: none !important;
    border-bottom: 1px solid var(--rule) !important;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 6px 8px !important;
    gap: 2px !important;
    flex-shrink: 0;
  }
  #group-settings-overlay [style*="width:168px"] > div:first-child,
  #group-settings-overlay [style*="width:168px"] > div:last-child {
    display: none !important; /* hide section labels and danger separator */
  }
  .gs-tab {
    white-space: nowrap;
    width: auto !important;
    padding: 6px 12px !important;
    flex-shrink: 0;
  }

  /* 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);
  }
  /* ── Hide grabby button on mobile ─────────────────────────────────────────*/
  .grabby-btn { 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;
  }
}
