/* Dokter Tani mobile layer. Linked after every reference stylesheet (and search.css), before motion.css.
 *
 * Rules of the house:
 *  - The look is Mas Bintang's: same tokens, type and components. This file only adds behaviour (safe areas, touch,
 *    sheets, snap) and invisible hit-area expansion. It never restyles a component on desktop.
 *  - Everything that could touch the desktop render sits inside a media query (<= 1050 / <= 900 / hover:none / pointer:coarse).
 *    The few global rules (touch-action, env() insets, overscroll on overlays) have no visual effect on a mouse screen.
 *  - Never `overscroll-behavior` on html/body (it would kill pull-to-refresh), never position:fixed on body.
 *  - Z-index map for fixed UI: header 20 (reference) > menu backdrop 19 > anything else the pages add. Leads UI
 *    (.wa-fab, .lead-sticky) is z-index 60: above the menu backdrop, hidden by leads.js while the menu is open. The install
 *    card is z-index 25, bottom-left, and never shown on product pages (where the sticky bar owns the bottom edge).
 */

/* ---------------------------------------------------------------- 1. Safe areas, viewport units, scroll lock */
:root {
  --dt-inset-t: env(safe-area-inset-top, 0px);
  --dt-inset-r: env(safe-area-inset-right, 0px);
  --dt-inset-b: env(safe-area-inset-bottom, 0px);
  --dt-inset-l: env(safe-area-inset-left, 0px);
  /* Horizontal room the floating WhatsApp button (.wa-fab: right 16 px + 56 px + 12 px gap + safe area) takes in the
   * bottom-right corner; the install card stops short of it. Vertical: the card (12 px + ~68 px) stays under the fab tooltip. */
  --dt-wa-clear: calc(84px + var(--dt-inset-r));
  --dt-ease: cubic-bezier(.45, 0, .55, 1); /* power2.inOut */
}
/* Header: pad for the status bar / notch (insets are 0 in a normal browser tab, so desktop is unchanged). */
.header { padding-top: var(--dt-inset-t); padding-left: var(--dt-inset-l); padding-right: var(--dt-inset-r); }
/* Landscape phones: keep the footer text out of the notch / gesture bar. */
.site-footer { padding-bottom: var(--dt-inset-b); }

/* Search overlay: svh-safe full height (vh fallback first), safe-area padding, no scroll chaining. */
.search-overlay { height: 100vh; height: 100dvh; overscroll-behavior: contain; }
.search-top { padding-top: calc(22px + var(--dt-inset-t)); padding-left: max(var(--dt-inset-l), 0px); padding-right: max(var(--dt-inset-r), 0px); }
.search-scroll { overscroll-behavior: contain; padding-bottom: var(--dt-inset-b); }

/* Scroll lock while a menu / dialog / search overlay is open. Touch and narrow screens only: on desktop the
 * ScrollSmoother is paused by the overlay itself and a hidden scrollbar would shift the layout. */
@media (max-width: 1050px), (pointer: coarse) {
  html.dt-menu-open,
  html:has(dialog[open]),
  html:has(#search-overlay:not([hidden])) { overflow: hidden; scrollbar-gutter: stable; }
}

/* ---------------------------------------------------------------- 2. Mobile menu (<= 1050 px), driven by site.js state */
@media (max-width: 1050px) {
  /* The reference hides the closed menu with display:none, which cannot animate: keep it laid out but invisible
   * (visibility:hidden removes it from the tab order and the accessibility tree, exactly like display:none). */
  .site-header nav {
    display: flex;
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-8px);
    overscroll-behavior: contain;
    transition: opacity .25s var(--dt-ease), transform .25s var(--dt-ease), visibility 0s linear .25s;
  }
  .site-header nav.open {
    visibility: visible;
    pointer-events: auto;
    opacity: 1;
    transform: none;
    padding-bottom: max(.8rem, var(--dt-inset-b));
    padding-left: max(clamp(1rem, 4vw, 3rem), var(--dt-inset-l));
    padding-right: max(clamp(1rem, 4vw, 3rem), var(--dt-inset-r));
    max-height: calc(100vh - 4.125rem - var(--dt-inset-t));
    max-height: calc(100dvh - 4.125rem - var(--dt-inset-t));
    transition: opacity .4s var(--dt-ease), transform .4s var(--dt-ease), visibility 0s;
  }
  html.dt-lite .site-header nav { transform: none; }
  .dt-menu-backdrop {
    position: fixed; inset: 0; z-index: 19;
    background: rgb(15 38 26 / .34);
    opacity: 0; visibility: hidden;
    transition: opacity .3s var(--dt-ease), visibility 0s linear .3s;
  }
  html.dt-menu-open .dt-menu-backdrop { opacity: 1; visibility: visible; transition-delay: 0s; }
}
@media (min-width: 1051px) { .dt-menu-backdrop { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .site-header nav, .site-header nav.open, .dt-menu-backdrop { transition: none; }
}

/* ---------------------------------------------------------------- 3. Touch */
a, button, summary, select, label, input, textarea, [role="tab"], [role="button"], .button { touch-action: manipulation; }
@media (hover: none), (pointer: coarse) {
  a, button, summary, label, [role="tab"], .button { -webkit-tap-highlight-color: transparent; }
  /* No text selection on controls (content stays selectable). */
  button, .button, summary, [role="tab"] { -webkit-user-select: none; user-select: none; }

  /* Pressed states, instant (feedback at touch-down), power2.inOut on release. Controls only: card transforms are
   * driven by GSAP reveals, so cards get an opacity change without any transition. */
  .button, .button-outline, button:not(.menu-toggle), summary, [role="tab"], .field-button, .catalog-filters summary,
  .crop-links > a, .commodity-list button, .article-pager a, .listing-pager a, .topic-chips a, .article-tags a,
  .family-tile, .assessment-choice, .text-link { transition-timing-function: var(--dt-ease); }
  .button:active, .field-button:active, .button-outline:active, .catalog-filter-open:active, .dt-sheet-apply:active { transform: scale(.97); transition-duration: .1s; }
  button:not(.button):not(.menu-toggle):active, summary:active, [role="tab"]:active,
  .crop-links > a:active, .topic-chips a:active, .article-tags a:active, .article-pager a:active, .listing-pager a:active,
  .family-tile:active, .assessment-choice:active { opacity: .72; }
  .menu-toggle:active { opacity: .6; }
  .site-header nav > a:active { background: var(--pale); }
  .catalog-card:active, .news-card:active, .komoditas-sector-card:active, .topic-card:active, .crop-guide-product:active { opacity: .86; }
  .text-link:active, .breadcrumbs > a:active, .site-footer a:active { opacity: .6; }
}

/* Hover-only effects: a tap leaves :hover stuck on touch screens. Neutralise the lifts, scales and fills the
 * reference puts on :hover so they only apply with a real hover pointer. */
@media (hover: none) {
  .button:hover { transform: none; background: var(--orange); }
  .button-outline:hover { background: white; }
  .header-consult:hover { background: var(--orange); border-color: var(--orange); }
  .topic-card:hover { transform: none; }
  .guide-grid > button:hover { transform: none; box-shadow: none; }
  .family-specimen:hover img { transform: none; }
  .news-photo:hover > img { transform: none; }
  .hero-packshot:hover { filter: none; }
  .category-stories > a:hover .circle-arrow { transform: none; }
  .catalog-card .product-visual:hover img { opacity: 1; }
  .catalog-card:hover .product-title, .text-link:hover, .catalog-card:hover .product-link { text-decoration: none; }
  .site-header nav > a:hover { background: transparent; }
  .site-header nav > a.is-active:hover { background: var(--pale); }
}

/* ---------------------------------------------------------------- 4. Tap targets (>= 44 px, visual design unchanged)
 * Each small control gets an invisible ::after hit box centred on it, at least 44 px tall (position:relative changes no
 * layout; padding/negative-margin tricks did, so they are not used). Hit boxes of neighbours may touch, never overlap by
 * more than a few px. */
@media (max-width: 900px) {
  :is(.breadcrumbs > a, .catalog-detail-family, .catalog-detail-nav a, .related-more a, .news-meta a, .article-tags a,
      .field-link, .field-examples a, .news-card h3 > a, .article-pager a, .listing-pager a, #article-share, .text-link,
      .catalog-quick-crops button, .catalog-view-options button, .catalog-active-filters button, .crop-links > a,
      .commodity-list button, .site-footer a:not(.brand), .site-header .menu-toggle) { position: relative; }
  :is(.breadcrumbs > a, .catalog-detail-family, .catalog-detail-nav a, .related-more a, .news-meta a, .article-tags a,
      .field-link, .field-examples a, .news-card h3 > a, .article-pager a, .listing-pager a, #article-share, .text-link,
      .catalog-quick-crops button, .catalog-view-options button, .catalog-active-filters button, .crop-links > a,
      .commodity-list button, .site-footer a:not(.brand))::after {
    content: ""; position: absolute; left: -6px; right: -6px; top: 50%; height: max(100%, 44px); transform: translateY(-50%);
  }
  .site-footer a:not(.brand)::after { left: -8px; right: -8px; }
  /* Header controls (40 px) and the brand */
  .site-header .brand { position: relative; }
  .site-header .menu-toggle::after { content: ""; position: absolute; inset: -3px; }
  .site-header .brand::after { content: ""; position: absolute; inset: -7px -4px; }
  .field-search input { min-height: 44px; }
}

/* ---------------------------------------------------------------- 5. Forms: no iOS zoom */
@media (max-width: 900px) {
  :root:root input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="submit"]):not([type="button"]),
  :root:root select, :root:root textarea { font-size: 16px; }
}

/* ---------------------------------------------------------------- 6. Image placeholders (mobile.js adds .dt-ph to a lazy image until it loads) */
@media (max-width: 900px) {
  img.dt-ph { background-color: var(--pale, #eff5ed); }
  .dt-slide { background-color: var(--pale, #eff5ed); }
}

/* ---------------------------------------------------------------- 7. Horizontally scrollable tab strips with snap */
@media (max-width: 740px) {
  .crop-guide-nav, .crop-guide-inner > * { min-width: 0; }
  .crop-guide-tabs {
    flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x proximity; scrollbar-width: none;
    margin-inline: -18px; padding-inline: 18px; scroll-padding-inline: 18px; padding-block: 2px;
  }
  .crop-guide-tabs::-webkit-scrollbar { display: none; }
  .crop-guide-tabs a { flex: none; white-space: nowrap; scroll-snap-align: start; }
}
@media (max-width: 800px) {
  .phase-tabs { scroll-snap-type: x proximity; overscroll-behavior-x: contain; scrollbar-width: none; scroll-padding-inline: 18px; }
  .phase-tabs::-webkit-scrollbar { display: none; }
  .phase-tabs > button { scroll-snap-align: start; }
}

/* ---------------------------------------------------------------- 8. Catalogue filters as a bottom sheet (<= 900 px) */
.catalog-filter-open, .dt-sheet { display: none; }
@media (max-width: 900px) {
  #solutions-app.has-filter-sheet .catalog-filter-open {
    display: inline-flex; align-items: center; gap: .55rem; min-height: 2.9rem; padding: .55rem 1.1rem;
    border: 1px solid var(--green, #215b3e); border-radius: 100px; background: white; color: var(--ink, #202e26);
    font: inherit; font-size: .9375rem; font-weight: 600; cursor: pointer;
  }
  #solutions-app.has-filter-sheet .catalog-filter-open svg { width: 1.1rem; height: 1.1rem; }
  #solutions-app.has-filter-sheet #catalog-refine { display: none; }
  #solutions-app.has-filter-sheet .catalog-filters { margin-bottom: .9rem; }

  dialog.dt-sheet {
    box-sizing: border-box; position: fixed; inset: auto 0 0 0; margin: 0; padding: 0; border: 0;
    width: 100%; max-width: none; height: auto;
    max-height: 85vh; max-height: 85svh;
    border-radius: 18px 18px 0 0; background: white; color: var(--ink, #202e26);
    font-family: inherit; overscroll-behavior: contain; overflow: hidden;
    flex-direction: column;
    box-shadow: 0 -12px 40px rgb(15 38 26 / .22);
    transform: translateY(100%);
    transition: transform .35s var(--dt-ease), overlay .35s allow-discrete, display .35s allow-discrete;
  }
  dialog.dt-sheet[open] { display: flex; transform: none; }
  @starting-style { dialog.dt-sheet[open] { transform: translateY(100%); } }
  dialog.dt-sheet::backdrop { background: rgb(15 38 26 / .45); transition: opacity .35s var(--dt-ease), overlay .35s allow-discrete, display .35s allow-discrete; opacity: 0; }
  dialog.dt-sheet[open]::backdrop { opacity: 1; }
  @starting-style { dialog.dt-sheet[open]::backdrop { opacity: 0; } }
  dialog.dt-sheet.is-dragging { transition: none; }
  .dt-sheet-handle { flex: none; display: grid; place-items: center; height: 1.9rem; touch-action: none; cursor: grab; }
  .dt-sheet-handle span { width: 2.6rem; height: .3rem; border-radius: 9px; background: #c9d6cc; }
  .dt-sheet-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 .6rem 0 1.25rem; }
  .dt-sheet-head h2 { margin: 0; font-size: 1.25rem; color: var(--forest-deep, #123a28); }
  .dt-sheet-close { display: grid; place-items: center; width: 3rem; height: 3rem; border: 0; background: none; border-radius: 50%; color: var(--forest, #174b33); cursor: pointer; }
  .dt-sheet-close svg { width: 1.4rem; height: 1.4rem; }
  .dt-sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: .4rem 1.25rem 1rem; }
  .dt-sheet-body .catalog-refine-body { padding: 0; }
  .dt-sheet-body .catalog-reset { display: none; }
  .dt-sheet-foot {
    flex: none; display: flex; align-items: center; gap: .8rem; padding: .8rem 1.25rem calc(.8rem + var(--dt-inset-b));
    border-top: 1px solid var(--line, #e3e8df); background: white;
  }
  .dt-sheet-reset { min-height: 3rem; padding: 0 .4rem; border: 0; background: none; color: var(--forest, #174b33); font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: .2em; cursor: pointer; }
  .dt-sheet-apply { flex: 1; min-width: 0; font-size: .9375rem; }
}
@media (max-width: 900px) and (prefers-reduced-motion: reduce) {
  dialog.dt-sheet { transform: none; opacity: 0; transition: opacity .2s linear, overlay .2s allow-discrete, display .2s allow-discrete; }
  dialog.dt-sheet[open] { opacity: 1; }
  @starting-style { dialog.dt-sheet[open] { opacity: 0; transform: none; } }
}

/* ---------------------------------------------------------------- 9. Product gallery swipe (touch; mobile.js/catalog.js builds .dt-track) */
.dt-track { display: none; }
@media (pointer: coarse) {
  .catalog-product-gallery.dt-swipe .catalog-product-photo { overflow: hidden; }
  .catalog-product-gallery.dt-swipe #catalog-full-image { display: none; }
  .catalog-product-gallery.dt-swipe .dt-track {
    display: flex; gap: .5rem; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .catalog-product-gallery.dt-swipe .dt-track::-webkit-scrollbar { display: none; }
  .dt-slide { flex: 0 0 88%; scroll-snap-align: start; scroll-snap-stop: always; aspect-ratio: 1 / 1; border-radius: .75rem; overflow: hidden; }
  .dt-slide a, .dt-slide img { display: block; width: 100%; height: 100%; }
  .dt-slide img { object-fit: contain; }
  .catalog-product-gallery.dt-swipe #catalog-gallery-prev, .catalog-product-gallery.dt-swipe #catalog-gallery-next { display: none; }
  .catalog-product-gallery.dt-swipe .catalog-gallery-controls > span {
    padding: .3rem .75rem; border-radius: 100px; background: var(--pale, #eff5ed); color: var(--forest, #174b33); font-weight: 600;
  }
  .catalog-product-gallery.dt-swipe .catalog-thumbnails { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; overscroll-behavior-x: contain; }
  .catalog-product-gallery.dt-swipe .catalog-thumbnails > button { flex: none; }
}

/* ---------------------------------------------------------------- 10. Fixed UI: PWA install card, never over the WhatsApp button */
.dt-install {
  position: fixed; z-index: 25; left: max(12px, var(--dt-inset-l));
  /* bottom-left, and never wider than the space left of the 56 px WhatsApp button (+ gaps + safe area) */
  right: calc(var(--dt-wa-clear) + 4px);
  bottom: calc(12px + var(--dt-inset-b));
  display: flex; align-items: center; gap: .65rem; padding: .7rem .5rem .7rem .8rem;
  background: white; color: var(--ink, #202e26); border: 1px solid var(--line, #d6e1d8); border-radius: 16px;
  box-shadow: 0 10px 30px rgb(15 38 26 / .18); font-size: .875rem; line-height: 1.35;
  transform: translateY(0); opacity: 1; transition: transform .3s var(--dt-ease), opacity .3s var(--dt-ease);
}
.dt-install[hidden] { display: none; }
.dt-install.is-entering { transform: translateY(16px); opacity: 0; }
.dt-install img { flex: none; width: 2.5rem; height: 2.5rem; border-radius: .6rem; }
.dt-install p { flex: 1; min-width: 0; margin: 0; }
.dt-install strong { display: block; font-size: .9375rem; color: var(--forest-deep, #123a28); white-space: nowrap; }
@media (max-width: 440px) { .dt-install img { display: none; } .dt-install p { font-size: .8125rem; } .dt-install .dt-install-go { padding: 0 .85rem; } }
.dt-install .dt-install-go { flex: none; min-height: 2.75rem; padding: 0 1rem; border: 0; border-radius: 100px; background: var(--forest, #174b33); color: white; font: inherit; font-weight: 600; cursor: pointer; }
.dt-install .dt-install-x { flex: none; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border: 0; background: none; color: var(--muted, #5b6b60); border-radius: 50%; cursor: pointer; }
.dt-install .dt-install-x svg { width: 1.1rem; height: 1.1rem; }
@media (min-width: 701px) { .dt-install { right: auto; max-width: 26rem; } }
@media (min-width: 1051px) { .dt-install { display: none; } }
@media print, (prefers-reduced-motion: reduce) { .dt-install { transition: none; } }
