/* ==========================================================================
   ChitChat — responsive rules (mobile-first app, desktop enhancements)
   ========================================================================== */

@media (max-width: 1279px) {
  :root {
    --rail-w: 0px;
  }

  .content-grid {
    grid-template-columns: minmax(0, 1fr);
    max-width: 760px;
  }

  .right-rail {
    display: none;
  }
}

@media (max-width: 1023px) {
  :root {
    --sidebar-w: 84px;
  }

  .sidebar {
    padding: 18px 10px;
    align-items: center;
    gap: 18px;
  }

  .brand {
    padding: 0;
  }

  .brand-word,
  .nav-item > span:not(.nav-icon):not(.nav-spark):not(.nav-badge),
  .sidebar-create span:last-child,
  .sidebar-me .me-meta,
  .sidebar-links a .icon,
  .sidebar-me .btn-icon {
    display: none;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .sidebar-nav {
    width: 100%;
    align-items: center;
    gap: 6px;
  }

  .nav-item {
    width: 52px;
    height: 48px;
    padding: 0;
    justify-content: center;
    border-radius: 14px;
  }

  .nav-spark {
    position: absolute;
    top: 9px;
    right: 10px;
  }

  .nav-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    margin: 0;
    min-width: 17px;
    height: 17px;
    font-size: 9.5px;
    padding: 0 4px;
  }

  .sidebar-create {
    width: 48px;
    height: 48px;
    padding: 0;
    border-radius: 14px;
  }

  .sidebar-create span:first-child {
    display: inline-flex;
  }

  .sidebar-footer {
    align-items: center;
    width: 100%;
  }

  .sidebar-me {
    justify-content: center;
    padding: 4px;
    width: 48px;
    height: 48px;
    border-radius: 14px;
  }

  .sidebar-me .avatar {
    width: 36px !important;
    height: 36px !important;
  }

  .sidebar-links {
    flex-direction: column;
    gap: 8px;
    justify-content: center;
  }

  .content-grid {
    padding: 0 20px;
  }
}

@media (max-width: 767px) {
  :root {
    --topbar-h: 60px;
    --max-content: 100%;
  }

  .app {
    grid-template-columns: minmax(0, 1fr);
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  .sidebar {
    display: none;
  }

  .topbar {
    position: sticky;
    padding: 0 14px;
    gap: 10px;
    height: var(--topbar-h);
  }

  .brand-mobile {
    display: flex;
    gap: 8px;
    padding: 0;
  }

  .brand-mobile .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .brand-mobile .brand-word {
    font-size: 20px;
  }

  .search-pill {
    display: none;
  }

  #topbar-search-mobile {
    display: inline-grid;
  }

  .topbar-settings-btn {
    display: inline-grid;
  }

  .topbar-actions {
    gap: 0;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
  }

  .topbar-avatar {
    display: none;
  }

  .content-grid {
    padding: 0;
    gap: 0;
  }

  .main-scroll {
    padding: 12px 12px 28px;
  }

  .bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    background: var(--glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    height: calc(62px + env(safe-area-inset-bottom));
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    border-radius: 12px;
    position: relative;
    transition: color var(--transition);
  }

  .bottom-nav-item .nav-icon .icon {
    width: 23px;
    height: 23px;
  }

  .bottom-nav-item.active {
    color: var(--primary);
  }

  .bottom-nav-item .badge-count {
    position: absolute;
    top: 0;
    right: calc(50% - 20px);
    height: 16px;
    min-width: 16px;
    font-size: 9px;
    padding: 0 4px;
  }

  .page-head {
    margin-bottom: 12px;
  }

  .page-head h1 {
    font-size: 23px;
  }

  .page-head p {
    font-size: 12.5px;
  }

  .card {
    border-radius: 18px;
    padding: 14px;
  }

  .post {
    padding: 12px;
    border-radius: 18px;
  }

  .post-body {
    font-size: 14px;
  }

  .composer {
    padding: 12px;
  }

  .composer-action span:last-child {
    display: none;
  }

  .composer-action {
    padding: 8px;
  }

  .action-btn span:not(.icon) {
    font-size: 11.5px;
  }

  .toast-stack {
    bottom: calc(74px + env(safe-area-inset-bottom));
  }

  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal-card {
    width: 100%;
    max-height: 92dvh;
    border-radius: 22px 22px 0 0;
    transform: translateY(28px);
  }

  .modal-overlay.visible .modal-card {
    transform: none;
  }

  .modal-wide {
    width: 100%;
  }

  .search-overlay .modal-card {
    margin-top: 0;
    align-self: flex-end;
    max-height: 88dvh;
  }

  /* Reels */
  .reels-page {
    height: calc(100dvh - var(--topbar-h) - 24px - 62px - env(safe-area-inset-bottom));
    min-height: 0;
    border-radius: 18px;
    margin: 0;
  }

  .reel-overlay {
    padding: 16px 14px 18px;
  }

  .reel-actions {
    right: 6px;
    bottom: 22px;
    gap: 11px;
  }

  .reel-action .icon-wrap {
    width: 38px;
    height: 38px;
  }

  .reel-action {
    font-size: 9.5px;
  }

  .reel-info {
    max-width: calc(100% - 62px);
  }

  .reel-top {
    padding: 12px 14px;
  }

  /* Friends */
  .user-grid {
    grid-template-columns: 1fr;
  }

  /* Messenger */
  .messenger-shell {
    grid-template-columns: 1fr;
    height: calc(100dvh - var(--topbar-h) - 130px - env(safe-area-inset-bottom));
    min-height: 380px;
    border-radius: 18px;
    position: relative;
  }

  .conv-pane {
    border-right: 0;
  }

  .messenger-shell.chat-open .conv-pane {
    display: none;
  }

  .messenger-shell:not(.chat-open) .chat-pane {
    display: none;
  }

  .messenger-mobile-back {
    display: inline-grid;
  }

  .chat-pane {
    height: 100%;
  }

  .chat-actions .icon-btn {
    width: 34px;
    height: 34px;
  }

  .chat-actions .hide-mobile {
    display: none;
  }

  .messages {
    padding: 12px 10px 4px;
  }

  .message {
    max-width: 88%;
  }

  .bubble {
    max-width: 100%;
  }

  .message-tools {
    opacity: 1;
  }

  /* Profile */
  .profile-cover {
    height: 140px;
  }

  .profile-content {
    padding: 0 14px 16px;
  }

  .profile-identity {
    margin-top: -38px;
    gap: 12px;
  }

  .profile-avatar-lg {
    width: 84px;
    height: 84px;
    border-width: 3px;
  }

  .profile-avatar-lg .avatar {
    width: 78px !important;
    height: 78px !important;
  }

  .profile-identity-main {
    padding-top: 42px;
  }

  .profile-identity h1 {
    font-size: 21px;
  }

  .profile-actions {
    padding-top: 0;
    width: 100%;
  }

  .profile-actions .btn {
    flex: 1;
  }

  .profile-grid {
    gap: 3px;
  }

  .profile-tile.text-tile {
    font-size: 10px;
    padding: 8px;
  }

  .profile-stats {
    gap: 16px;
  }

  .profile-stat strong {
    font-size: 15px;
  }

  /* Notifications */
  .notif-panel {
    width: 100vw;
    border-left: 0;
  }

  .notif-panel .modal-header {
    padding-top: calc(14px + env(safe-area-inset-top));
  }

  /* Calls */
  .call-video-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: 1fr;
    gap: 6px;
  }

  .call-tile.local {
    position: absolute;
    right: 12px;
    bottom: 12px;
    width: 108px;
    height: 148px;
    z-index: 5;
    box-shadow: var(--shadow-lg);
  }

  .call-tile.local video {
    object-fit: cover;
  }

  .call-stage {
    padding: 8px;
  }

  .call-controls {
    gap: 9px;
    padding: 12px 10px calc(14px + env(safe-area-inset-bottom));
  }

  .call-btn {
    width: 48px;
    height: 48px;
  }

  .call-top {
    padding: 10px 14px;
  }

  .hide-mobile {
    display: none !important;
  }

  .incoming-card {
    border-radius: 22px;
  }

  .config-card {
    padding: 22px;
    border-radius: 22px;
  }

  .config-card h1 {
    font-size: 21px;
  }
}

@media (max-width: 380px) {
  .brand-mobile .brand-word {
    display: none;
  }

  .reel-info {
    max-width: calc(100% - 56px);
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}

/* Very short landscape phones */
@media (max-height: 560px) and (max-width: 767px) {
  .reels-page {
    height: calc(100dvh - var(--topbar-h) - 62px - 16px);
  }

  .bottom-nav {
    height: calc(54px + env(safe-area-inset-bottom));
  }

  .bottom-nav-item span:last-child {
    display: none;
  }
}

/* Print */
@media print {
  .sidebar,
  .topbar,
  .bottom-nav,
  .right-rail,
  .post-actions,
  .composer,
  .toast-stack {
    display: none !important;
  }

  .app {
    display: block;
  }

  .content-grid {
    display: block;
  }

  body {
    background: #fff;
    color: #000;
  }
}
