/* ========================================================
   DISCX RESPONSIVE / TOUCH LAYOUT
   Loaded last so it can safely adapt the desktop interface.
   ======================================================== */
.mobile-app-header,
.mobile-bottom-nav,
.mobile-drawer-backdrop {
  display: none;
}
.members-sidebar.is-hidden { display: none; }
.dock-control-btn:disabled,
.dock-secondary-action:disabled {
  cursor: not-allowed;
  opacity: .42;
  filter: saturate(.4);
}

@supports (-webkit-touch-callout: none) {
  body,
  #app-root,
  .discx-app { height: -webkit-fill-available; }
}

@media (max-width: 820px) {
  :root { --mobile-header-height: 56px; --mobile-nav-height: 66px; }

  html,
  body,
  #app-root {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body { touch-action: manipulation; }

  .auth-page {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    align-items: flex-start;
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  }
  .auth-container { width: 100%; max-width: 520px; margin: auto; }
  .auth-card-panel { width: 100%; padding: 24px 18px; gap: 19px; border-radius: 18px; }
  .auth-card-title { font-size: 20px; }
  .auth-row-options { gap: 12px; font-size: 11px; }
  .auth-social-btn { min-width: 0; padding: 10px 5px; font-size: 11px; }
  .auth-help-card { padding: 12px; font-size: 11px; }

  .discx-app {
    position: relative;
    display: block;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    padding-top: calc(var(--mobile-header-height) + env(safe-area-inset-top));
    padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    overflow: hidden;
  }

  .mobile-app-header {
    position: absolute;
    z-index: 130;
    inset: 0 0 auto;
    height: calc(var(--mobile-header-height) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 10px 0;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid rgba(255,255,255,.075);
    background: rgba(7, 12, 23, .97);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
  }

  .mobile-header-action {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 13px;
    background: #111a2c;
    color: #a9b1c7;
  }
  .mobile-header-action[aria-expanded="true"] { color: #fff; border-color: rgba(120,103,255,.55); background: rgba(101,83,238,.2); }
  .mobile-header-action[hidden] { visibility: hidden; pointer-events: none; }
  .mobile-header-action svg { width: 19px; height: 19px; }

  .mobile-header-copy {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    font: 750 14px var(--font-heading);
  }
  .mobile-header-copy img { width: 28px; height: 28px; }
  .mobile-header-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .mobile-bottom-nav {
    position: absolute;
    z-index: 130;
    inset: auto 0 0;
    min-height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    padding: 5px 7px env(safe-area-inset-bottom);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    border-top: 1px solid rgba(255,255,255,.075);
    background: rgba(7, 12, 23, .98);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
  }
  .mobile-bottom-nav button {
    min-width: 0;
    min-height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    border: 0;
    border-radius: 13px;
    background: transparent;
    color: #6f7b91;
    font: 650 9px var(--font-sans);
  }
  .mobile-bottom-nav button svg { width: 19px; height: 19px; }
  .mobile-bottom-nav button.active { color: #c8c5ff; background: rgba(103,87,241,.14); }

  .mobile-drawer-backdrop {
    position: absolute;
    z-index: 99;
    inset: calc(var(--mobile-header-height) + env(safe-area-inset-top)) 0 calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    border: 0;
    background: rgba(0, 3, 10, .68);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  .mobile-servers-open .mobile-drawer-backdrop,
  .mobile-channels-open .mobile-drawer-backdrop { display: block; opacity: 1; pointer-events: auto; }

  #server-sidebar-mount,
  #channel-sidebar-mount {
    position: absolute;
    z-index: 110;
    top: calc(var(--mobile-header-height) + env(safe-area-inset-top));
    bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    left: 0;
    height: auto;
    transform: translateX(-105%);
    transition: transform .22s cubic-bezier(.22,.8,.28,1);
    box-shadow: 22px 0 55px rgba(0,0,0,.45);
  }
  #server-sidebar-mount { width: 82px; }
  #channel-sidebar-mount { width: min(310px, 86vw); }
  .mobile-servers-open #server-sidebar-mount,
  .mobile-channels-open #channel-sidebar-mount { transform: translateX(0); }
  #server-sidebar-mount .server-sidebar,
  #channel-sidebar-mount .channel-sidebar { width: 100%; min-width: 0; height: 100%; }
  #server-sidebar-mount .server-sidebar { padding-block: 10px; }

  #main-content-mount {
    width: 100%;
    height: 100% !important;
    min-width: 0;
    overflow: hidden !important;
  }
  #main-content-mount > * { min-width: 0; }

  .right-widget-column { display: none; }

  /* Chat */
  .main-stage-container { width: 100%; min-width: 0; }
  .main-stage-header { min-height: 54px; height: 54px; padding: 0 12px; gap: 8px; }
  .header-left-info { min-width: 0; }
  .header-channel-title { min-width: 0; font-size: 15px; }
  .header-channel-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .header-channel-topic,
  .header-search-bar,
  .header-right-actions > .mini-icon-btn[title="Mensagens Fixadas"] { display: none; }
  .header-right-actions { gap: 4px; }
  .header-right-actions .mini-icon-btn { width: 40px; height: 40px; }

  .chat-messages-scroll { padding: 14px 8px; gap: 12px; }
  .message-group { gap: 9px; padding: 5px 3px; }
  .message-avatar { width: 34px; height: 34px; }
  .message-meta { min-width: 0; flex-wrap: wrap; gap: 4px 6px; }
  .message-author { max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
  .message-timestamp { font-size: 9px; }
  .message-content { font-size: 13px; line-height: 1.48; }
  .attachment-img { max-width: 100%; height: auto; }
  .rich-embed-card { width: 100%; max-width: 100%; }
  .message-actions-toolbar { position: static; display: flex; width: fit-content; margin-top: 5px; order: 8; }
  .toolbar-btn { min-width: 36px; min-height: 34px; }
  .typing-indicator-bar { padding-inline: 12px; }
  .chat-input-wrapper { padding: 0 8px 9px; }
  .chat-input-bar { gap: 6px; padding: 6px 7px; border-radius: 14px; }
  .chat-attach-btn { flex: 0 0 38px; width: 38px; height: 38px; }
  .chat-textarea { min-width: 0; font-size: 16px; }
  .chat-input-actions { gap: 1px; }
  .chat-input-actions .chat-emoji-btn { width: 36px; height: 38px; padding: 7px; }
  .chat-input-actions #btn-emoji-gift { display: none; }
  .chat-input-actions .btn { min-width: 40px; min-height: 38px; padding: 7px 9px !important; }

  .members-sidebar {
    position: absolute;
    z-index: 85;
    inset: calc(var(--mobile-header-height) + env(safe-area-inset-top) + 54px) 0 calc(var(--mobile-nav-height) + env(safe-area-inset-bottom)) auto;
    display: flex !important;
    width: min(310px, 86vw);
    min-width: 0;
    transform: translateX(105%);
    transition: transform .22s ease;
    box-shadow: -20px 0 50px rgba(0,0,0,.45);
  }
  .members-sidebar.is-mobile-open { transform: translateX(0); }

  .members-close-btn {
    display: inline-flex;
    flex: 0 0 auto;
  }

  /* Home and server dashboards */
  .dashboard-page { width: 100%; padding: 12px 10px 24px; }
  .dashboard-hero { min-height: 0; padding: 20px 16px; border-radius: 18px; }
  .dashboard-hero-copy h1 { font-size: clamp(22px, 7vw, 30px); }
  .dashboard-hero-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .dashboard-hero-actions .btn { width: 100%; padding: 10px; font-size: 10px; }
  .dashboard-metric-grid { grid-template-columns: repeat(2, minmax(0,1fr)) !important; gap: 8px; }
  .dashboard-metric { min-width: 0; padding: 12px; }
  .dashboard-columns,
  .dashboard-columns.lower { grid-template-columns: 1fr !important; gap: 10px; }
  .dashboard-panel { padding: 14px; border-radius: 16px; }
  .dashboard-server-grid { grid-template-columns: 1fr; }
  .dashboard-server-card { min-height: 68px; }
  .dashboard-side-stack { grid-template-rows: auto; }

  /* Friends and private messages */
  .social-layout { height: 100%; flex-direction: column; }
  .social-sidebar {
    display: flex !important;
    width: 100%;
    min-width: 0;
    height: auto;
    max-height: 118px;
    flex: 0 0 auto;
    border-right: 0;
    border-bottom: 1px solid var(--border-subtle);
    overflow: hidden;
  }
  .social-sidebar-search,
  .social-sidebar-title,
  .social-me { display: none; }
  .social-sidebar nav { flex: 0 0 auto; flex-direction: row; gap: 4px; padding: 6px 7px 3px; overflow-x: auto; }
  .social-sidebar nav button { flex: 1 0 auto; min-height: 40px; justify-content: center; padding: 8px 10px; white-space: nowrap; }
  .social-conversation-list { min-height: 0; flex: 0 0 60px; flex-direction: row; gap: 4px; padding: 3px 7px 7px; overflow-x: auto; overflow-y: hidden; }
  .social-conversation-list button { width: auto; min-width: 54px; height: 52px; justify-content: center; padding: 5px; }
  .social-conversation-list img { width: 38px; height: 38px; }
  .social-conversation-list button > span { display: none; }
  .social-conversation-list button > b { position: absolute; margin: -28px 0 0 27px; }
  .social-main { min-height: 0; }
  .social-main-header { min-height: 52px; padding: 0 12px; }
  .social-main-header strong { max-width: 65vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
  .social-content-scroll { padding: 10px 8px 22px; gap: 12px; }
  .social-add-card { padding: 13px; }
  .social-add-card form { align-items: stretch; flex-wrap: wrap; }
  .social-add-card form .btn { width: 100%; }
  .social-person-row { align-items: flex-start; padding: 10px 8px; flex-wrap: wrap; }
  .social-person-copy { width: calc(100% - 54px); }
  .social-person-actions { width: 100%; justify-content: flex-end; }
  .social-person-actions .btn { min-height: 36px; }
  .social-dm-view .chat-messages-scroll { padding-top: 10px; }

  /* Calls */
  .voice-arena-container { height: 100%; }
  .voice-controls-dock { padding-bottom: env(safe-area-inset-bottom); }
  .mobile-in-call { padding-bottom: env(safe-area-inset-bottom); }
  .mobile-in-call .mobile-bottom-nav { display: none; }
  .mobile-in-call .members-sidebar { bottom: env(safe-area-inset-bottom); }
  .voice-stage-area.is-sharing { padding: 7px; gap: 7px; }
  .screenshare-display-box { border-radius: 12px; }
  .screenshare-top-overlay { inset: 8px 8px auto; }
  .stream-quality-tag { padding: 5px 7px; font-size: 9px; }
  .participants-filmstrip { flex-basis: 84px; grid-auto-columns: 130px; }

  /* Settings and overlays */
  .modal-overlay { padding: 0; align-items: stretch; }
  .settings-modal-dialog {
    width: 100vw;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    grid-template-columns: 66px minmax(0,1fr);
    border: 0;
    border-radius: 0;
  }
  .settings-nav-sidebar { padding: 12px 7px; }
  .settings-nav-title { display: none; }
  .settings-nav-item { min-height: 44px; justify-content: center; gap: 0; padding: 9px; font-size: 0; border-left: 0; }
  .settings-nav-item svg { width: 19px; height: 19px; }
  .settings-content-panel { padding: 18px 12px 24px; gap: 15px; }
  .settings-panel-title { font-size: 18px; }
  .settings-panel-desc { font-size: 11px; }
  .settings-grid-two-col { grid-template-columns: 1fr; gap: 14px; }
  .settings-footer-actions { position: sticky; bottom: -24px; gap: 7px; margin-inline: -12px; padding: 12px; background: rgba(9,15,27,.97); }
  .settings-footer-actions .btn { flex: 1; min-width: 0; padding: 9px; font-size: 10px; }
  .account-summary-card { grid-template-columns: 1fr; }
  .profile-settings-card { align-items: flex-start; flex-wrap: wrap; }
  .quality-plan-card { align-items: flex-start; }
  .modal-overlay > .admin-panel-dialog { width: 100vw !important; max-width: none !important; height: 100dvh !important; max-height: none !important; border-radius: 0 !important; }
  #admin-modal-content > div { padding: 18px 12px !important; }
  #admin-modal-content [style*="grid-template-columns: repeat(4"] { grid-template-columns: repeat(2, minmax(0,1fr)) !important; gap: 8px !important; }
  #admin-modal-content [style*="overflow-x:auto"] { margin-inline: -4px; }

  .media-picker-popover { max-width: calc(100vw - 12px); border-radius: 15px; }
  .gif-results-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .toast-container { right: 8px; bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom) + 8px); left: 8px; }
  .toast { width: 100%; min-width: 0; }

  button,
  .btn,
  .channel-item,
  .channel-nav-item { -webkit-tap-highlight-color: transparent; }
}

@media (max-width: 460px) {
  .dashboard-metric-grid { grid-template-columns: repeat(2, minmax(0,1fr)) !important; }
  .dashboard-hero-actions { grid-template-columns: 1fr; }
  .dashboard-panel-title { align-items: flex-start; }
  .dashboard-panel-title small { display: none; }
  .chat-input-actions #btn-emoji-gif { display: none; }
  .message-badge-role { display: none; }
  .presenter-tag span { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .direct-call-ringing-actions { gap: 30px; }
  .direct-call-controls { gap: 2px; padding-inline: 4px; }
  .call-control { min-width: 62px; }
}

@media (hover: none), (pointer: coarse) {
  .server-btn:hover,
  .dashboard-server-card:hover,
  .dock-control-btn:hover { transform: none; }
  .message-actions-toolbar { display: flex; }
  .btn,
  button { touch-action: manipulation; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
