/**
 * @brief Chestnut Modern, a theme for Dotclear 2
 *
 * Responsive breakpoints. Loaded last (after style.css and the active
 * fixed.css/fluid.css) so its overrides reliably win regardless of which
 * width mode is selected. Two breakpoints:
 *   - 1023px and below ("tablet"): loosen the desktop-only #page width
 *     lock, drop the home grid to 2 columns.
 *   - 767px and below ("mobile"): stack #main/#sidebar, collapse the
 *     home grid to 1 column, switch the header to a normal-flow layout,
 *     and turn the top navigation into a toggleable panel.
 *
 * @package Dotclear
 * @subpackage Theme
 *
 * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
 */

/* Tablet: loosen the fixed/fluid desktop width lock
-------------------------------------------------------- */
@media (max-width: 1023px) {
  #page {
    width: auto !important;
    min-width: 0 !important;
    margin: 0 12px !important;
  }
  #footer,
  #legal {
    width: auto !important;
  }
  #nav, #menu, #navsm {
    width: auto !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  :root {
    --cm-home-columns: 2;
  }
}

/* Mobile: single column, stacked header, toggleable nav
-------------------------------------------------------- */
@media (max-width: 767px) {
  #page {
    margin: 0 !important;
    box-shadow: none;
  }
  #wrapper {
    width: auto !important;
    padding: 16px 12px;
  }

  /* Header: normal flow instead of a fixed-height, absolute-positioned band */
  #top {
    height: auto;
    padding: 12px 0;
  }
  #toplinks {
    height: auto;
    padding: 6px 0;
    overflow: visible;
  }
  #toplinks .left {
    display: block;
    float: none;
    margin: 2px 12px;
  }
  #top h1 {
    position: static;
    margin: 0;
    padding: 0;
    font-size: 2.2em;
    line-height: 1.2em;
    flex: 1 1 auto;
    min-width: 0;
  }
  .chestnutmodern-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px 0;
  }
  #top #description {
    position: static;
    width: auto;
    margin: 0;
    padding: 4px 12px 10px;
  }
  #topsearch {
    position: static;
    width: auto;
    height: auto;
    margin: 0 12px 12px;
  }
  #topsearch p {
    width: auto;
  }
  #topsearch #query {
    width: 70%;
  }

  /* Nav toggle button (hidden on desktop, see style.css). Sits in the
     title row (.chestnutmodern-top-row) now, so no standalone margin. */
  .chestnutmodern-nav-toggle {
    display: inline-flex;
    flex-shrink: 0;
    margin: 0;
  }

  /* Top navigation: collapsed behind the toggle by default, and floats
     as an overlay when opened (position: absolute) rather than pushing
     the rest of the page down. top: 100% anchors it to the bottom edge
     of #top, which -- now that the nav is out of #top's normal flow --
     sizes itself to just the title/description/search content above. */
  #container_menu,
  #nav,
  #navsm {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 5000;
    margin: 0 12px 12px !important;
    max-height: 60vh;
    overflow-y: auto;
    border-radius: 4px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
  }
  #container_menu.chestnutmodern-nav-open,
  #nav.chestnutmodern-nav-open,
  #navsm.chestnutmodern-nav-open {
    display: block;
  }

  /* Stack menu items vertically instead of floating them horizontally --
     all three menu styles (category menu, Menu plugin, simpleMenu) share
     this treatment since only one is active at a time. */
  #menu,
  #nav ul,
  #navsm {
    height: auto !important;
  }
  #menu li,
  #nav li,
  #navsm li {
    float: none !important;
    display: block !important;
    margin: 0 !important;
  }
  #container_menu .chestnutmodern-menu-sep,
  #nav .chestnutmodern-menu-sep,
  #navsm .chestnutmodern-menu-sep {
    display: none !important;
  }
  #menu a,
  #nav li a,
  #navsm a {
    float: none !important;
    display: block !important;
    padding: 8px 4px !important;
  }
  #navsm li::before {
    content: none;
  }

  /* Submenus: no hover on touch, so keep them permanently expanded and
     inline rather than absolutely positioned flyouts. */
  .submenu,
  #nav ul ul {
    position: static !important;
    left: auto !important;
    top: auto !important;
    display: block !important;
    margin: 0 0 4px 16px !important;
    box-shadow: none !important;
  }

  /* Main content / sidebar: single column */
  #main,
  #sidebar {
    float: none;
    width: auto !important;
    padding: 0 !important;
  }
  #sidebar {
    margin-top: 24px;
  }

  /* Home page grid: single column */
  :root {
    --cm-home-columns: 1;
  }
  .dc-home .category-container {
    gap: 24px;
  }
  .dc-home #content .post-title {
    font-size: 20px;
    line-height: 24px;
  }
  .dc-home #content .post-content {
    font-size: 1.45em;
    line-height: 1.5em;
  }

  /* Category listing page: same summary-text size bump as the home page
     (this was missing before -- only the home page grid had one) */
  .dc-category #content .post-content {
    font-size: 1.45em;
    line-height: 1.5em;
  }

  /* Related posts (post/page): stacked instead of 2-up */
  .dc-post .post-related .post,
  .dc-page .post-related .post,
  .dc-post .post-related .even,
  .dc-page .post-related .even {
    float: none !important;
    width: auto !important;
    margin: 0 0 20px 0 !important;
  }

  /* Comment form: name/email/site fields stack instead of sitting side by side */
  #comment-form #c_namemail div {
    width: 100% !important;
    float: none;
  }
  #comment-form #c_namemail input#c_name,
  #comment-form #c_namemail input#c_mail,
  #comment-form #c_namemail input#c_site {
    width: 90% !important;
  }

  /* Pagination (previous/next entries + numbered page links): "previous
     entries" / "next entries" are too long to sit side by side at a
     readable size on a phone-width screen, so instead of an awkward
     half-fit, each becomes a clear, deliberate full-width row (bigger
     than desktop), followed by a visibly separated section (top border
     + margin) for the numbered links, so the grouping reads as
     intentional rather than accidental wrapping. */
  .pagination {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }
  .pagination .prev,
  .pagination .next {
    float: none;
    max-width: none;
    margin: 0 0 10px;
    justify-content: center;
    font-size: 17px;
    padding: 16px 18px;
  }
  .pagination p {
    margin: 10px 0 0;
    padding-top: 14px;
    border-top: 1px solid #e2e2e2;
    text-align: center;
  }
  .pagination p span {
    min-width: 44px;
    height: 44px;
    padding: 0 12px;
    font-size: 17px;
  }

  /* Single-post prev/next navigation: same bigger, full-width treatment */
  #navlinks {
    display: flex;
    flex-direction: column;
  }
  #navlinks .prev,
  #navlinks .next {
    float: none;
    max-width: none;
    margin: 0 0 10px;
    justify-content: center;
    font-size: 17px;
    padding: 16px 18px;
  }

  /* Footer widget columns: stacked instead of 4-up */
  #custom div {
    width: 100% !important;
    float: none;
    height: auto !important;
  }

  /* Wide tables: scroll horizontally instead of overflowing the viewport */
  #content table {
    display: block;
    width: auto !important;
    max-width: 100% !important;
    overflow-x: auto;
    white-space: nowrap;
  }

  /* Post-body images have a fixed 690px cap in style.css for desktop
     layouts; that alone doesn't shrink on a narrow viewport, so it needs
     an explicit override here. max-width via #content img is safe (the
     home grid thumbnails already set their own width:100%), but height
     is deliberately NOT touched through #content img -- its higher
     specificity would otherwise override the home grid cards' fixed
     140px thumbnail height. */
  #content img,
  .post-content img,
  .post-excerpt img {
    max-width: 100% !important;
  }
  .post-content img,
  .post-excerpt img {
    height: auto;
  }

  /* Belt-and-braces: nothing else should ever be wider than the viewport.
     Kept deliberately low-specificity (plain element selector) so it
     never overrides more specific sizing rules, such as the home grid
     thumbnails' fixed height + object-fit above. */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Slider: stack the image and the text overlay instead of the fixed
     absolute-positioned side-by-side layout */
  #slider {
    width: auto !important;
    height: auto;
  }
  #slider .slider-container {
    float: none;
    width: 100% !important;
  }
  #slider .slider-container .image-container {
    height: auto;
  }
  #slider .featured-post {
    position: static;
    width: auto;
    height: auto;
    padding: 12px 0 0;
  }
}

@media (max-width: 420px) {
  #top h1 {
    font-size: 1.8em;
  }
}
