/* ===== Tablet ≤1024px ===== */
@media (max-width: 1024px) {
  /* minmax(0, 1fr), not a bare 1fr: a grid item's default min-width is auto (its content's
     intrinsic size), so a wide code line or table inside .article-body was stretching the
     whole column - and the page - past the viewport instead of scrolling internally
     (reported "mobile doesn't respond" bug). The desktop rule already has this via
     minmax(0, var(--reading-width)); the mobile override was dropping it. */
  .article-layout { grid-template-columns: minmax(0, 1fr); max-width: var(--reading-width); margin: 0 auto; }
  .article-toc { display: none; }
  .article-toc-mobile { display: block; }

  .home-grid { grid-template-columns: minmax(0, 1fr); }
  .article-index-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .related-articles__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .admin-sidebar { position: fixed; left: 0; top: 0; z-index: 80; transform: translateX(-100%); transition: transform var(--transition-base); background: var(--bg); width: 260px; max-width: 85vw; box-shadow: var(--shadow-2); }
  .admin-shell.is-nav-open .admin-sidebar { transform: translateX(0); }
  /* minmax(0, 1fr): see the article-layout comment above - the admin shell's single remaining
     column had the same gap, and a long post title or wide code block in the editor preview
     stretched the whole admin page sideways instead of wrapping/scrolling in place (reported
     "the whole page isn't responding" bug). */
  .admin-shell { grid-template-columns: minmax(0, 1fr); }
  .admin-topbar { display: flex; }
  .admin-main { padding: var(--sp-5) var(--sp-4) var(--sp-8); }

  /* The hamburger button sat inside the topbar at the same stacking level as the sidebar
     (both effectively below it in paint order once the sidebar's fixed overlay opened), so once
     open there was nothing left to click to close it again (reported bug) - lifting just the
     button above the sidebar's z-index keeps it reachable in both states. A backdrop (added
     below, admin.js; base display:none lives in admin.css - see note there) gives a second,
     more usual way to dismiss it: tap outside. */
  .admin-topbar [data-admin-nav-toggle] { position: relative; z-index: 85; }
  .admin-shell.is-nav-open .admin-backdrop { display: block; }

  .editor-meta-grid { grid-template-columns: minmax(0, 1fr); }

  /* .admin-topbar (above) is also sticky at top:0 here - offset the toolbar by the topbar's own
     rendered height (2 * 12px padding + 36px icon-btn + 1px border) so the two don't overlap once
     both are stuck. */
  .editor-toolbar { top: 61px; }
}

/* ===== Small tablet / large phone ≤768px ===== */
@media (max-width: 768px) {
  .container { padding: 0 var(--sp-4); }

  .nav-toggle { display: inline-flex; }
  .search-trigger span:not(.eyebrow), .search-trigger kbd { display: none; }
  /* Same footprint as the other two header buttons (.icon-btn: 36x36) - it used to just get
     padding:8px with no fixed size, so it rendered smaller and off-centre next to them. */
  .search-trigger { width: 36px; height: 36px; padding: 0; justify-content: center; }

  .site-header__bar { height: 56px; }

  /* Mobile nav: links collapse into a dropdown panel toggled by the hamburger button.
     align-items: stretch overrides the desktop rule's "center" (correct there, for a
     horizontal row of nav items - wrong here, where flex-direction is column: it was
     shrinking each link to its own text width and centering it, so the border-bottom
     "underline" only ever spanned the word instead of the full row (reported bug). */
  .site-nav__links {
    display: none;
    position: absolute;
    left: 0; right: 0; top: 56px;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: var(--sp-2) var(--sp-4) var(--sp-4);
    box-shadow: var(--shadow-1);
  }
  .site-nav__links a {
    display: block; /* an inline element (the <a> default) ignores width entirely - the 100%
      below was a no-op without this, which is the other half of the underline/row-width bug */
    padding: var(--sp-3) 0;
    border-bottom: 1px solid var(--border);
    width: 100%;
    text-align: center;
  }
  .site-nav.is-open .site-nav__links { display: flex; }

  .page-head { padding: var(--sp-6) 0 var(--sp-5); }
  .page-head__title { font-size: 30px; }

  .article-header__title { font-size: 30px; }
  .article-header__byline { flex-direction: column; align-items: flex-start; }

  .article-index-grid { grid-template-columns: minmax(0, 1fr); }
  .related-articles__grid { grid-template-columns: minmax(0, 1fr); }
  .topic-pill-grid { flex-direction: column; }
  .topic-pill { min-width: 0; }

  .editor-panes { grid-template-columns: minmax(0, 1fr); }
  .editor-tabs { display: flex; }
  .editor-pane[data-pane="preview"] { display: none; }
  .editor-shell.is-preview .editor-pane[data-pane="editor"] { display: none; }
  .editor-shell.is-preview .editor-pane[data-pane="preview"] { display: flex; }

  .editor-actions { flex-direction: column; align-items: stretch; }
  .editor-actions__group { justify-content: stretch; }
  .editor-actions__group .btn { flex: 1; }

  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .site-footer__row { flex-direction: column; }
  .site-footer__legal { flex-direction: column; }

  .palette-overlay { padding: 0; align-items: stretch; }
  .palette { max-width: none; height: 100%; border-radius: 0; display: flex; flex-direction: column; }
  .palette__results { max-height: none; flex: 1; }
}

/* ===== Phone ≤480px ===== */
@media (max-width: 480px) {
  body { font-size: 15px; }
  .page-head__title { font-size: 26px; }
  .article-header__title { font-size: 26px; }
  .article-body { font-size: 16.5px; }
  .stat-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .data-table th, .data-table td { padding: var(--sp-2) var(--sp-3); font-size: 13px; }
  .admin-main { padding: var(--sp-4) var(--sp-3) var(--sp-7); }
  .mc-modal { padding: var(--sp-5); }
}

/* ===== Wide desktop ===== */
@media (min-width: 1600px) {
  .container { max-width: 1360px; }
}
