/* ============================================================
   Desktop & tablet overrides — loads AFTER components.css so it
   wins via cascade order. Phone view (<700px) is left fully
   untouched: nothing in this file fires below 700px width.

   Tiers:
     700-1023 px  : tablet  — wider centered column, bigger type
     1024 px +    : desktop — full app chrome, 2-up category grid,
                              wide detail modal, premium feel
   Pointer-gating: we DON'T require pointer:fine here because a
   1280px viewport on a touch laptop should still get the desktop
   layout. components.css's existing rule was pointer:fine — we
   override that for the same widths via cascade order + specificity.

   No new colors. Reuses tokens via var(). Local aliases only when
   we need a value derived from an existing token.
============================================================ */

/* ---------- TABLET (700-1023): widen the existing phone column ---------- */
@media (min-width: 700px) and (max-width: 1023px) {
  /* Override components.css 480px ceiling. Phone-style layout stays — just
     more breathing room for tablet portrait + small landscape. */
  #app {
    max-width: 640px;
  }
  .detail,
  .settings-overlay {
    max-width: 640px;
  }
  /* Sample row gets a touch more side air. */
  .sample-row {
    padding: 16px 22px;
  }
  .search-bar {
    padding: 10px 22px 14px;
  }
  .cat-group > summary {
    padding: 16px 22px;
  }
  .sub-header {
    padding: 14px 22px 4px;
  }
}


/* ============================================================
   DESKTOP (≥ 1024 px)
============================================================ */
@media (min-width: 1024px) {

  /* ---- local tokens ---- */
  :root {
    --d-app-max:     1280px;      /* full app shell width */
    --d-content-max: 1140px;       /* inner content (cards, header inner) */
    --d-detail-max:  1080px;       /* detail modal width */
    --d-side-pad:    32px;
    --d-header-h:    72px;
    --d-radius:      14px;
  }

  /* ---- page chrome: dark void around the centered app shell ---- */
  body {
    background:
      radial-gradient(60% 70% at 50% 0%, rgba(212, 168, 87, 0.05) 0%, transparent 60%),
      #07070a;
  }

  /* ---- app shell ---- */
  /* Override components.css 480px column. Use !important sparingly only on
     the max-width since the components.css selector has identical specificity
     and would otherwise win on source order if the user reordered links.
     (They won't — we own the order in index.html — but defensive.) */
  #app {
    max-width: var(--d-app-max);
    margin: 0 auto;
    min-height: 100dvh;
    /* drop the phone-column borders + shadow from components.css */
    border-left: 0;
    border-right: 0;
    box-shadow: none;
    background: var(--bg);
  }

  /* ---- header bar: brand left | search center | actions right ---- */
  /* The existing markup is:
       <header class="app-header">
         <button #settings-btn>⚙</button>
         <h1 class="app-title">Stone Ridge Spirits & Wine Sample App</h1>
         <div class="app-meta"><span #sample-count/></div>
       </header>
     We restyle that 3-col grid into a desktop top bar. The settings gear
     moves to the right; the title becomes a left-aligned brand mark; the
     sample-count chip sits next to the gear. */
  .app-header {
    grid-template-columns: 1fr auto auto;
    grid-template-areas: "brand count actions";
    column-gap: 18px;
    padding: 14px var(--d-side-pad);
    border-bottom: 1px solid var(--line);
    min-height: var(--d-header-h);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    background: rgba(26, 26, 29, 0.92);
  }
  .app-title {
    grid-area: brand;
    text-align: left;
    font-size: 17px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--fg);
    position: relative;
    padding-left: 30px;
    line-height: 1.2;
    align-self: center;
    /* truncate the long title to "SRSW · Sample App" feel — use ::before
       for a gold dot mark and ::after to mask overflow if needed */
  }
  .app-title::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background:
      radial-gradient(circle at 35% 30%, #e8c178 0%, #d4a857 55%, #a17a2f 100%);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  }
  .app-meta {
    grid-area: count;
    align-self: center;
    font-size: 12px;
    letter-spacing: 0.02em;
    color: var(--fg-dim);
    padding: 6px 12px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    white-space: nowrap;
  }
  .settings-btn {
    grid-area: actions;
    justify-self: end;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-2);
    border: 1px solid var(--line);
    font-size: 18px;
    transition: background var(--t-fast) ease-out, border-color var(--t-fast) ease-out, transform var(--t-fast) ease-out;
  }
  .settings-btn:hover {
    background: var(--bg-3);
    border-color: rgba(212, 168, 87, 0.4);
  }
  .settings-btn:active { transform: scale(0.94); }

  /* ---- search bar: full-width, pinned under header, centered input ---- */
  /* Pull the search bar out of the cramped phone-column treatment and let
     it read as a desktop search row. */
  .search-bar {
    padding: 18px var(--d-side-pad) 18px;
    top: var(--d-header-h);
    background: linear-gradient(180deg, var(--bg) 0%, rgba(26,26,29,0.92) 100%);
    border-bottom: 1px solid var(--line);
  }
  /* Inner wrap: center the input and cap its width so it doesn't sprawl. */
  .search-bar input {
    display: block;
    max-width: 640px;
    margin: 0 auto;
    padding: 14px 18px 14px 46px;
    font-size: 15px;
    border-radius: 10px;
    background:
      url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a8a29a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='8'/><path d='m21 21-4.3-4.3'/></svg>") no-repeat 16px center,
      var(--bg-2);
    background-size: 18px 18px, auto;
  }

  /* ---- results region: constrained content column ---- */
  .results-region,
  .sample-index {
    max-width: var(--d-content-max);
    margin: 0 auto;
    width: 100%;
    padding-left: var(--d-side-pad);
    padding-right: var(--d-side-pad);
    box-sizing: border-box;
  }
  /* Avoid double padding when .sample-index lives inside .results-region.
     The outer .results-region handles side padding; the inner index resets. */
  .results-region > .sample-index {
    padding-left: 0;
    padding-right: 0;
    max-width: none;
  }
  .sample-index {
    padding-bottom: calc(var(--safe-bottom) + 48px);
  }

  /* ---- category accordion: 2-column at desktop, 3-column wide ----
     Categories collapse independently. CSS grid puts them in a grid;
     each <details> stays an independent open/close unit. */
  .results-region > .sample-index {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 32px;
    align-items: start;
  }
  /* When showing search results (flat .sample-row list, no <details>), the
     ".search-results" class is added — go back to a single column with cards
     stacked, but make them roomier. */
  .results-region > .sample-index.search-results {
    display: block;
  }
  .results-region > .sample-index.search-results .sample-row {
    max-width: 720px;
    margin: 0 auto;
  }

  /* Category group as a card-like block */
  .cat-group {
    border-bottom: 0;
    border: 1px solid var(--line);
    border-radius: var(--d-radius);
    background: var(--bg);
    margin-bottom: 18px;
    overflow: hidden;
    transition: border-color var(--t-fast) ease-out;
  }
  .cat-group:hover {
    border-color: rgba(212, 168, 87, 0.35);
  }
  /* Category summary loses sticky positioning — the grid layout makes
     sticky summaries collide across columns. */
  .cat-group > summary {
    position: static;
    padding: 16px 20px;
    background: var(--bg-2);
    border-radius: var(--d-radius);
    transition: background var(--t-fast) ease-out;
  }
  .cat-group[open] > summary {
    border-bottom: 1px solid var(--line);
    border-radius: var(--d-radius) var(--d-radius) 0 0;
  }
  .cat-group > summary:hover { background: var(--bg-3); }
  .cat-name { font-size: 15px; }
  .cat-count {
    background: var(--bg);
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--fg-dim);
    font-variant-numeric: tabular-nums;
  }

  /* sample row: refined desktop row, hover lift, more horizontal padding */
  .sample-row {
    padding: 12px 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.03);
    transition: background 0.12s, padding-left 0.12s;
  }
  .cat-group .sample-row:first-child {
    border-top: 0;
  }
  .sample-row:hover {
    background: var(--bg-2);
    padding-left: 22px;
  }
  .sample-row .name strong {
    font-size: 15px;
    font-weight: 500;
  }
  .sample-row .name small {
    font-size: 12px;
  }
  .sample-row .loc {
    font-size: 13px;
    padding: 4px 10px;
    background: rgba(212, 168, 87, 0.10);
    color: var(--accent);
    border-radius: 8px;
    font-weight: 600;
  }
  .sample-row .thumb {
    flex: 0 0 48px;
    width: 48px;
    height: 48px;
    border-radius: 6px;
  }

  /* sub-headers within a category group */
  .sub-header {
    padding: 14px 20px 6px;
    background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 100%);
  }

  /* ---- detail view: wide centered modal, no longer phone-shaped ---- */
  /* Components.css set `.detail { left:50%; transform:translateX(-50%); max-width:480px }`
     for the 700px+pointer:fine tier. Override to a generous reading width. */
  .detail {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--d-detail-max);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    /* keep the proximity scroll-snap from components.css desktop rule */
    scroll-snap-type: y proximity;
    background:
      radial-gradient(80% 60% at 50% 0%, rgba(212, 168, 87, 0.04) 0%, transparent 60%),
      var(--bg);
    animation: none;
  }

  /* Detail close-button: top-right desktop chrome instead of top-left
     phone "back" arrow style. Bigger hit target with text label. */
  .detail-back {
    top: 22px;
    left: auto;
    right: 22px;
    width: auto;
    height: 44px;
    padding: 0 18px 0 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.10);
    font-size: 0;             /* hide the literal "‹" glyph */
    color: var(--fg);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background var(--t-fast) ease-out, border-color var(--t-fast) ease-out;
  }
  .detail-back::before {
    content: "← Back to samples";
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.01em;
  }
  .detail-back:hover {
    background: rgba(255, 255, 255, 0.10);
    border-color: rgba(212, 168, 87, 0.45);
  }

  /* Pencil edit button — pair with back button on right side, sits to the left of it */
  .detail-edit {
    top: 22px;
    right: 192px;             /* clear of back button */
    width: 44px;
    height: 44px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.10);
  }
  .detail-edit:hover {
    background: rgba(255, 255, 255, 0.10);
    border-color: rgba(212, 168, 87, 0.45);
  }

  /* Hero nav arrows — bigger, more visible, anchored to detail edges */
  .hero-nav {
    width: 56px;
    height: 88px;
    border-radius: 14px;
    font-size: 38px;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0.9;
  }
  .hero-nav-prev { left: 24px; }
  .hero-nav-next { right: 24px; }

  /* Detail cards: lose the scroll-snap-stop:always and 100dvh feel for a
     desktop-friendly continuous read. Cards still snap softly via the
     `scroll-snap-type: y proximity` on .detail above. */
  .card {
    min-height: 88dvh;        /* leave a little headroom above next card */
    padding: 88px 64px 72px;
    scroll-snap-stop: normal;
  }
  .card-title {
    font-size: 44px;
    line-height: 1.1;
    max-width: 22ch;
  }
  .card-body, .card-prose {
    max-width: 64ch;
  }

  /* Hero card: keep image full-bleed but constrain text content to a
     comfortable reading column with extra bottom anchoring. */
  .card-hero {
    padding-top: 0;
  }
  .card-hero .hero-content {
    max-width: 720px;
  }
  .card-hero .card-title {
    font-size: 56px;
  }
  .card-hero .hero-loc {
    font-size: 22px;
  }

  /* The Drink card: the 4-block stack centers nicely; just give it more
     vertical breathing and wider tasting/fact blocks. */
  .card-story {
    padding-left: 80px;
    padding-right: 80px;
  }
  .card-story .tasting-block { max-width: 38ch; }
  .card-story .fun-fact-block { max-width: 44ch; }
  .card-story .origin-header .origin-place {
    font-size: clamp(48px, 4.5vw, 72px);
    max-width: 18ch;
  }

  /* The Backstory card: side-by-side description + meta pattern */
  .card-maker {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr);
    gap: 48px;
    align-items: start;
    padding: 96px 80px 80px;
  }
  .card-maker .card-label {
    grid-column: 1 / -1;
    font-size: 13px;
  }
  .card-maker > .card-prose:first-of-type {
    grid-column: 1 / 2;
  }
  .card-maker .meta-stack {
    grid-column: 2 / 3;
    grid-row: 2 / span 4;
    margin-top: 0;
  }
  .card-maker .backstory-block {
    grid-column: 1 / 2;
  }

  /* Scroll-hint reposition since the hero now has wide padding */
  .scroll-hint {
    bottom: 32px;
    right: 64px;
    font-size: 12px;
  }

  /* ---- settings overlay: same wide modal treatment as detail ---- */
  .settings-overlay {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 100%;
    max-width: 720px;
    max-height: calc(100dvh - 64px);
    margin-top: 32px;
    border-radius: var(--d-radius);
    border: 1px solid var(--line);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    animation: none;
  }
  .settings-header {
    padding: 18px 28px 14px;
  }
  .settings-header h2 {
    font-size: 20px;
  }
  .settings-main {
    padding: 24px 28px calc(var(--safe-bottom) + 32px);
    max-height: calc(100dvh - 64px - 60px);
    overflow-y: auto;
  }

  /* ---- customer mode: catalog-style premium layout ----
     Customer mode is gated by `pointer:coarse` in JS, so it doesn't fire on
     a real desktop. BUT if a user manually adds body[data-mode="customer"]
     (touchscreen laptop, demo, future toggle), give it the desktop treatment
     it deserves: full-bleed hero left, info column right with generous type. */
  body[data-mode="customer"] .detail {
    max-width: none;
    left: 0;
    transform: none;
    border: 0;
  }
  body[data-mode="customer"] .customer-view {
    grid-template-columns: 1.2fr 1fr;
  }
  body[data-mode="customer"] .customer-info {
    padding: 64px 80px;
    gap: 24px;
    max-width: 720px;
  }
  body[data-mode="customer"] .customer-info h2 {
    font-size: clamp(40px, 4vw, 60px);
  }
  body[data-mode="customer"] .customer-info .tasting {
    font-size: clamp(20px, 1.7vw, 26px);
    line-height: 1.45;
    max-width: 28ch;
  }

  /* ---- edit page: 2-column form layout for less scrolling ---- */
  .edit-page {
    max-width: var(--d-detail-max);
    margin: 0 auto;
    min-height: 100dvh;
  }
  .edit-header {
    padding: 22px 32px 16px;
  }
  .edit-form {
    padding: 28px 32px calc(var(--safe-bottom) + 48px);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 24px;
  }
  /* Some fields want full width — textareas, image preview, action row.
     Use :has selectors so they span both columns. */
  .edit-form .edit-field:has(textarea),
  .edit-form .edit-field:has(.image-preview),
  .edit-form .edit-actions,
  .edit-form .edit-status {
    grid-column: 1 / -1;
  }
  .edit-actions {
    flex-direction: row;
    justify-content: flex-end;
    gap: 12px;
  }
  .edit-actions .primary-btn {
    min-width: 200px;
    width: auto;
  }

  /* ---- save bar: float as a centered desktop bar instead of full-bleed ---- */
  .save-bar {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    bottom: 32px;
    width: auto;
    min-width: 480px;
    max-width: 720px;
    padding: 14px 20px;
    border-radius: 999px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--line);
  }

  /* ---- toast: nudged down + centered to whole viewport ---- */
  .toast {
    bottom: 40px;
    font-size: 14px;
  }

  /* ---- focus rings: more visible on dark desktop bg ---- */
  .sample-row:focus-visible,
  .cat-group > summary:focus-visible,
  .settings-btn:focus-visible,
  .detail-back:focus-visible,
  .detail-edit:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: var(--r-sm);
  }
}


/* ============================================================
   WIDE DESKTOP (≥ 1440 px) — 3-column category grid
============================================================ */
@media (min-width: 1440px) {
  .results-region > .sample-index {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0 28px;
  }
}


/* ============================================================
   SETTINGS OVERLAY BACKDROP — dim the page behind the settings
   modal on desktop. The phone treatment is full-screen takeover;
   on desktop a centered modal with a dim works better.
============================================================ */
@media (min-width: 1024px) {
  /* Pseudo-element approach: the settings-overlay's parent #settings-mount
     becomes the backdrop layer. Use a body-level ::before via the body
     selector when the mount has content. We can't reliably detect
     "settings is open" in CSS without :has — but :has has wide support
     now on desktop browsers. Light-touch implementation: add a tinted
     overlay using body:has(.settings-overlay) ::before. */
  body:has(.settings-overlay)::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 99;
    pointer-events: none;
    animation: settings-backdrop-in 200ms ease-out;
  }
  @keyframes settings-backdrop-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }
}
