
:root { --app-height: 100vh; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 270px minmax(0, 1fr); }
  .content { width: 100%; }
  .posts-grid { grid-template-columns: 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
}

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; min-height: var(--app-height); }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(86vw, 340px);
    height: var(--app-height);
    transform: translateX(-100%);
    transition: transform var(--normal) var(--ease);
    z-index: 40;
    border-right: 1px solid var(--line);
  }
  .sidebar.is-open { transform: translateX(0); }
  .mobile-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(4, 8, 14, .54);
    backdrop-filter: blur(6px);
    z-index: 39;
  }
  .mobile-backdrop.is-open { display: block; }
  .mobile-menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: start;
  }
  .topbar .auth-actions { grid-column: 1 / -1; }
  .hero-copy h2 { font-size: 28px; line-height: 1.12; }
  .messages-layout { grid-template-columns: 1fr; }
  .messages-sidebar, .messages-main { min-height: 0; }
  .mobile-tabbar { display: grid; }
  .content {
    padding: 18px 18px 100px;
    width: 100%;
  }
}

@media (max-width: 768px) {
  body { overscroll-behavior-y: none; }
  .content { padding: 14px 14px 100px; gap: 16px; }
  .hero-card, .card-soft, .post-view, .profile-card, .messages-main, .messages-sidebar { padding: 16px; border-radius: 20px; }
  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
  }
  #quickMessagesBtn { display: none; }
  .toolbar { grid-template-columns: 1fr; }
  .hero-meta { gap: 10px; }
  .hero-stat, .stat, .badge, .role-chip, .status-chip { padding: 9px 12px; }
  .section-head { align-items: flex-start; }
  .posts-grid { grid-template-columns: 1fr; gap: 14px; }
  .post-card { padding: 16px; }
  .profile-header { align-items: flex-start; }
  .register-code-row,
  .dm-form { grid-template-columns: 1fr; }
  .dm-form { position: sticky; bottom: calc(8px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--panel) 96%, transparent); padding-top: 12px; }
  .dm-form textarea { min-height: 52px; }
  .dm-messages { min-height: 48vh; max-height: none; height: calc(var(--app-height) - 310px); padding-bottom: 10px; }
  .message-row { gap: 8px; }
  .message-bubble { max-width: 86%; }
  .dm-topbar .status-chip { display: none; }
  .dm-back-btn { display: inline-flex; align-items: center; justify-content: center; }
  .messages-layout.has-active-chat .messages-sidebar { display: none; }
  .messages-layout.has-active-chat .messages-main { display: grid; }
  .messages-layout:not(.has-active-chat) .messages-main { display: none; }
  .messages-main {
    min-height: calc(var(--app-height) - 220px);
    align-content: start;
  }
}

@media (max-width: 560px) {
  .brand h1 { font-size: 20px; }
  .hero-copy h2 { font-size: 24px; }
  .hero-copy p { font-size: 14px; }
  .nav-link, .ghost-btn, .primary-btn, .pill-btn, .counter-btn, .tab { padding: 11px 12px; }
  .comment-form-actions,
  .post-actions,
  .auth-actions,
  .profile-stats,
  .profile-header,
  .favorite-item,
  .hero-meta,
  .section-badges { gap: 10px; }
  .post-actions { flex-direction: column; align-items: stretch; }
  .post-actions > .row:last-child { width: 100%; justify-content: space-between; }
  .message-bubble { max-width: 90%; padding: 11px 12px 9px; }
  .mini-avatar { width: 38px; height: 38px; border-radius: 12px; }
  .avatar { width: 64px; height: 64px; border-radius: 18px; }
  .mobile-tabbar { left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); }
  .mobile-tab { padding: 11px 8px; font-size: 13px; }
}

body.is-telegram {
  min-height: var(--app-height);
}
body.is-telegram .content {
  padding-top: max(14px, env(safe-area-inset-top));
  padding-bottom: calc(100px + env(safe-area-inset-bottom));
}


@media (max-width: 768px) {
  .messages-main {
    padding: 14px;
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(10, 18, 34, 0.96), rgba(10, 18, 34, 0.88));
  }
  .dm-topbar {
    padding: 2px 0 12px;
    gap: 10px;
  }
  .dm-banner {
    gap: 10px;
    padding: 12px;
    border-radius: 16px;
    margin-bottom: 8px;
  }
  .dm-banner__title {
    font-size: 12px;
  }
  .dm-banner__text {
    font-size: 12px;
  }
  .dm-messages {
    gap: 8px;
    padding: 4px 2px 8px;
    height: calc(var(--app-height) - 300px);
  }
  .message-row {
    gap: 7px;
  }
  .tiny-avatar {
    width: 26px;
    height: 26px;
    border-radius: 9px;
    font-size: 11px;
  }
  .message-bubble {
    max-width: 84%;
    padding: 12px 14px 10px;
    border-radius: 20px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255,255,255,.04);
  }
  .message-bubble.from-me {
    background: linear-gradient(180deg, rgba(109,168,255,.30), rgba(109,168,255,.20));
  }
  .message-meta {
    margin-top: 5px;
    font-size: 11px;
  }
  .dm-form {
    grid-template-columns: minmax(0,1fr) auto;
    align-items: end;
    gap: 10px;
    padding-top: 10px;
    padding-bottom: calc(2px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(2,8,23,0), rgba(2,8,23,.64) 18%, rgba(2,8,23,.94));
    backdrop-filter: blur(10px);
  }
  .dm-form textarea {
    min-height: 52px;
    max-height: 112px;
    border-radius: 18px;
    padding: 14px 16px;
    resize: none;
  }
  .dm-form .primary-btn {
    min-width: 54px;
    height: 52px;
    padding: 0 16px;
    border-radius: 18px;
    box-shadow: 0 10px 24px rgba(72,128,233,.20);
  }
}

@media (max-width: 560px) {
  .messages-main {
    padding: 12px;
    border-radius: 22px;
  }
  .dm-topbar strong {
    font-size: 15px;
  }
  .dm-topbar .muted {
    font-size: 12px;
  }
  .dm-messages {
    height: calc(var(--app-height) - 286px);
  }
  .message-bubble {
    max-width: 86%;
    padding: 11px 13px 9px;
    border-radius: 18px;
  }
  .message-text {
    font-size: 15px;
    line-height: 1.38;
  }
  .message-meta {
    font-size: 10px;
  }
  .dm-form {
    gap: 8px;
  }
  .dm-form .primary-btn {
    min-width: 50px;
    height: 50px;
    padding: 0 14px;
  }
}
