/* ---------- Large desktop tweaks ---------- */
@media (max-width: 1399px) {
  :root { --aside-w: 288px; --sidebar-w: 232px; }
  .grid-3.auto { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { grid-template-columns: 1fr; }
  .hero-feed { display: none; }
}

/* ---------- Tablet: 768–1199 ---------- */
@media (max-width: 1199px) {
  .shell,
  body.sidebar-collapsed .shell,
  body.no-aside .shell,
  body.sidebar-collapsed.no-aside .shell { grid-template-columns: var(--sidebar-rail) minmax(0, 1fr); }
  .aside { display: none; }
  .sidebar .lbl, .sidebar .count, .sidebar .side-label, .sidebar .side-footer, .sidebar .side-more, .sidebar .side-collapse { display: none; }
  .sidebar .side-link { justify-content: center; padding: 10px; }
  .sidebar .side-sep { display: block; }
  .header-nav { display: none; }
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .footer-grid { grid-template-columns: 1fr 1fr; }
  .dash-layout { grid-template-columns: minmax(0, 1fr); }
  .dash-nav { position: static; flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .dash-nav button { white-space: nowrap; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  body.layout-auth .shell { grid-template-columns: minmax(0, 1fr); }
  .mobile-token { display: block; }
}

/* Drawer used on tablet & mobile when user opens the menu */
@media (max-width: 1199px) {
  body.drawer-open .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 160; width: 280px; height: 100vh;
    background: var(--panel); padding: var(--s-5) var(--s-3); border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg); animation: drawerIn var(--t) var(--ease);
  }
  body.drawer-open .sidebar .lbl, body.drawer-open .sidebar .count,
  body.drawer-open .sidebar .side-label, body.drawer-open .sidebar .side-footer,
  body.drawer-open .sidebar .side-more { display: revert; }
  body.drawer-open .sidebar .side-label { display: flex; }
  body.drawer-open .sidebar .side-link { justify-content: flex-start; padding: 8px 10px; }
  body.drawer-open .sidebar .side-sep { display: none; }
  body.drawer-open .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 150; background: var(--overlay); }
  @keyframes drawerIn { from { transform: translateX(-100%); } to { transform: none; } }
}

/* ---------- Mobile: < 768 ---------- */
@media (max-width: 767px) {
  :root { --header-h: 56px; }
  .header-inner { padding: 0 var(--s-3); gap: var(--s-2); }
  .brand-word { display: none; }
  .search-trigger { max-width: none; }
  .search-trigger .kbd, .search-trigger span { display: none; }
  .search-trigger { flex: 0 0 38px; width: 38px; padding: 0; justify-content: center; margin: 0 0 0 auto; }
  .header-actions { margin-left: 0; }
  .header-actions .submit-btn, .header-actions .theme-btn { display: none; }
  .shell,
  body.sidebar-collapsed .shell,
  body.no-aside .shell,
  body.sidebar-collapsed.no-aside .shell { grid-template-columns: minmax(0, 1fr); padding: 0 var(--s-4); gap: 0; }
  .sidebar { display: none; }
  body.drawer-open .sidebar { display: block; }
  .main { padding: var(--s-4) 0 calc(var(--bottom-nav-h) + var(--s-10)); }

  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 110;
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel); border-top: 1px solid var(--border);
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; font-weight: 600; color: var(--text-3); }
  .bottom-nav a[aria-current='page'] { color: var(--accent); }
  .bottom-nav a.bn-submit .bn-ic { width: 38px; height: 30px; border-radius: 10px; background: var(--btn-bg); color: var(--btn-text); display: grid; place-items: center; }
  .fab {
    display: grid; place-items: center; position: fixed; right: 16px; z-index: 105;
    bottom: calc(var(--bottom-nav-h) + 16px + env(safe-area-inset-bottom));
    width: 52px; height: 52px; border-radius: 16px; background: var(--btn-bg); color: var(--btn-text); box-shadow: var(--shadow-md);
  }
  body.hide-fab .fab { display: none; }
  .toasts { left: 16px; right: 16px; bottom: calc(var(--bottom-nav-h) + 16px); }
  .toast { min-width: 0; max-width: none; }

  h1 { font-size: var(--fs-2xl); }
  .hero { padding: var(--s-5); }
  .hero h1 { font-size: 1.95rem; }
  .hero-sub { font-size: var(--fs-base); }
  .hero-search { flex-direction: column; }
  .hero-stats { gap: var(--s-4); }
  .grid-2, .grid-3, .grid-4, .grid-3.auto { grid-template-columns: minmax(0, 1fr); }
  .toolbar .select-sm { flex: 1 1 calc(50% - 8px); width: auto !important; }
  .toolbar .input-icon { flex: 1 1 100%; max-width: none !important; }
  .grid-2.keep-mobile { grid-template-columns: 1fr 1fr; }
  .grid.is-list .card { flex-direction: column; align-items: stretch; }
  .grid.is-list .card .card-foot { flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .feature-list { grid-template-columns: 1fr; }
  .shots { grid-template-columns: 1fr 1fr; }
  .page-head h1 { font-size: var(--fs-xl); }
  .detail-head { flex-direction: column; gap: var(--s-3); }
  .detail-head h1 { font-size: var(--fs-xl); }
  .post-card { padding: var(--s-3) var(--s-4); gap: var(--s-3); }
  .post-card .vote-col { width: 36px; }
  .chips.scroll-mobile { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--s-4)); padding: 0 var(--s-4); }
  .chips.scroll-mobile::-webkit-scrollbar { display: none; }
  .toolbar .seg.icons { display: none; }
  .steps .step span.lbl { display: none; }
  .steps .step { justify-content: center; }
  .modal-root { padding: var(--s-3); align-items: flex-end; }
  .modal { max-height: 88vh; }
  .search-dialog { max-height: 88vh; }
  .footer-grid { grid-template-columns: 1fr; }
  .profile-card { padding: 0 var(--s-4) var(--s-5); }
  .topic-hero { padding: var(--s-4); }
  .auth-card { padding: var(--s-5); }
  .table th, .table td { padding: 8px 10px; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }
}

@media (min-width: 768px) {
  .mobile-only { display: none !important; }
}
.mobile-token { display: none; }
body.no-aside:not(.layout-auth) .mobile-token { display: block; max-width: 420px; }
@media (max-width: 767px) { .hide-xs { display: none; } }
