/* ============================================================
   Small-tablet and dual-screen tuning (Surface Duo and friends).

   1. From 32rem up to the desktop breakpoint the home stats sit in one
      compact row instead of a 2x2 block, and the feedback button lines
      up beside the bottom nav instead of floating above it.
   2. When the page spans two screens (Viewport Segments API), the
      desktop sidebar gives way to the bottom nav on the left screen,
      dialogs open on the left screen, and the home page splits into a
      doses pane (left) and a stats pane (right) so nothing sits under
      the hinge. Browsers without the API ignore that block.

   Loaded after the other app sheets; Tailwind utilities live in a
   cascade layer, so these unlayered rules override them.
   ============================================================ */

@media (min-width: 32rem) {
    .home-stat-strip {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.5rem;
    }

    .home-stat-strip > .lg-tile {
        padding: 0.75rem;
    }

    .home-stat-strip .lg-stat-caption {
        margin-bottom: 0.25rem;
        font-size: 0.6875rem;
        letter-spacing: 0.06em;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* The ring drops under the value instead of overflowing the tile
       when a long value (100.0%) meets a narrow tile. */
    .home-stat-strip .lg-tile > div {
        flex-wrap: wrap;
        gap: 0.375rem;
    }

    .home-stat-strip .font-data {
        font-size: 1.125rem;
        line-height: 1.5rem;
    }

    .home-stat-strip svg {
        width: 1rem;
        height: 1rem;
    }
}

@media (min-width: 48rem) {
    .home-stat-strip > .lg-tile {
        padding: 1rem;
    }

    .home-stat-strip .font-data {
        font-size: 1.5rem;
        line-height: 2rem;
    }

    .home-stat-strip svg {
        width: 1.25rem;
        height: 1.25rem;
    }
}

/* Feedback button: vertically centred on the 26rem bottom nav and
   centred in the gutter beside it (2rem button, 4.35rem nav). */
@media (min-width: 32rem) and (max-width: 63.9375rem) {
    body:has(#bottom-nav.dashboard-bottom-nav) #feedback-btn {
        right: max(0.5rem, calc((100vw - 26rem) / 4 - 1rem));
        bottom: calc(max(1.5rem, env(safe-area-inset-bottom, 0px) + 0.75rem) + 1.175rem);
    }
}

@media (horizontal-viewport-segments: 2) {
    .dashboard-app-shell {
        padding-top: calc(env(safe-area-inset-top, 0px) + 1rem);
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 7rem);
    }

    .dashboard-sidebar {
        display: none;
    }

    .dashboard-app-shell .lg\:ml-\[260px\] {
        margin-left: 0;
    }

    #bottom-nav.dashboard-bottom-nav {
        display: block;
        left: 0;
        width: env(viewport-segment-width 0 0);
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
    }

    /* Dialogs centre on the left screen; the right screen keeps the dim layer. */
    .journal-app .modal-backdrop {
        padding-left: 1rem;
        padding-right: calc(
            env(viewport-segment-width 1 0)
            + env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0)
            + 1rem
        );
    }

    /* The cookie notice moves to the right screen so it never covers the nav.
       `body` outweighs legal.css, which loads after this sheet. */
    body .cookie-notice {
        left: calc(env(viewport-segment-left 1 0) + 1rem);
        right: auto;
        bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        max-width: min(24rem, calc(env(viewport-segment-width 1 0) - 2rem));
    }

    /* Home: left pane = header + today's doses, right pane = rings + widgets.
       The rings span the header row and the next one, so the doses start
       right under the header while the widgets start under the rings. */
    .home-layout {
        display: grid;
        grid-template-columns: env(viewport-segment-width 0 0) env(viewport-segment-width 1 0);
        grid-template-rows: auto auto 1fr;
        column-gap: calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0));
        row-gap: 1.25rem;
        align-items: start;
        max-width: none;
        margin: 0;
        padding: 0;
    }

    .home-layout > *,
    .home-columns > * {
        min-width: 0;
        margin: 0;
        padding-inline: 1.25rem;
    }

    .home-layout__head {
        grid-column: 1;
        grid-row: 1;
        padding-top: 1.25rem;
    }

    .home-stat-strip {
        display: none;
    }

    /* 9rem keeps the fixed 6rem ring inside the tile padding; narrower
       right screens drop to fewer columns instead of overflowing. */
    .home-rings {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
        grid-column: 2;
        grid-row: 1 / span 2;
        padding-top: 1.25rem;
    }

    .home-columns {
        display: contents;
    }

    .home-columns__main {
        grid-column: 1;
        grid-row: 2 / span 2;
    }

    .home-columns__side {
        grid-column: 2;
        grid-row: 3;
    }
}
