/* Kelwise Dining — phone layer. Loaded after dining.css; every rule here is media-scoped
   (≤760px wide, plus short landscape phones up to 1024px wide). Class names follow the approved
   reference (Kelwise_Dining_Focused_Swipe.html, its `.phone.swipe-focus` rules) and the DOM
   contract in notes/T-20261202-27-dining-session-one/BUILD_PLAN.md. Owner: builder C.
   Design intent: the photo is the interface. The card takes the full content width, the photo
   area takes whatever height is left under 100dvh after header / toolbar / quick chips / deck
   title / card caption / fixed actions strip / fixed bottom nav. Nothing scrolls in swipe view. */

@media (max-width: 760px), ((max-width: 1024px) and (max-height: 520px) and (orientation: landscape)) {
  :root {
    --kwd-phone-header-h: 50px;      /* .header height on phones (set below) */
    --kwd-nav-h: 54px;               /* .web-nav height without the safe-area inset */
    --kwd-actions-h: 86px;           /* .phone-actions strip height (fixed, deterministic) */
    --kwd-gutter: 10px;              /* page side gutter; card = 100% - 2*gutter */
    --kwd-safe-t: env(safe-area-inset-top, 0px);
    --kwd-safe-b: env(safe-area-inset-bottom, 0px);
    --kwd-safe-l: env(safe-area-inset-left, 0px);
    --kwd-safe-r: env(safe-area-inset-right, 0px);
  }

  /* ---- viewport + iOS Safari quirks ------------------------------------------------------ */
  html { height: 100%; height: -webkit-fill-available; -webkit-text-size-adjust: 100%; }
  body { min-height: 100vh; min-height: -webkit-fill-available; overflow-x: hidden; overscroll-behavior-y: contain; }
  @supports (height: 100dvh) { body { min-height: 100dvh; } }
  button, [role=button], a.btn, .chip, .web-nav a, .web-nav button, .action-item, .photo-nav, .map-pin, .listing .pic {
    -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  }
  /* 16px stops iOS Safari from zooming the page when a field gets focus. */
  .page input, .dialog input, .dialog select, .dialog textarea, .searchline input, .home-search input { font-size: 16px; }
  .desktop-only { display: none !important; }
  .mobile-only { display: flex; }
  .mobile-only.block { display: block; width: 100%; }

  /* ---- header (compact) ------------------------------------------------------------------- */
  /* Selectors carry a `body` prefix so this layer beats the desktop rules ported from the reference
     (e.g. `.swipe-focus .header`, `.swipe-focus .page.focus-page`) on specificity, not just order. */
  body .header, .swipe-focus .header, body.swipe-focus .header {
    height: var(--kwd-phone-header-h); min-height: var(--kwd-phone-header-h); gap: 8px;
    padding: 0 max(var(--kwd-gutter), var(--kwd-safe-r)) 0 max(var(--kwd-gutter), var(--kwd-safe-l));
  }
  .header .nav, .header .loc { display: none; }
  .header .logo { font-size: 24px; }
  .header .logo img, .header .logo svg { height: 22px; width: auto; }
  .header .brand-section { font-size: 11px; padding-left: 8px; }
  .header-right { gap: 6px; }
  .header-right .iconbtn { width: 44px; height: 44px; }
  .header-right .btn { min-height: 40px; padding: 6px 10px; font-size: 12px; }

  /* ---- pages: one column, room for the fixed bottom nav ----------------------------------- */
  body .page {
    max-width: none; margin: 0;
    padding: 12px max(var(--kwd-gutter), var(--kwd-safe-r)) calc(16px + var(--kwd-nav-h) + var(--kwd-safe-b)) max(var(--kwd-gutter), var(--kwd-safe-l));
  }
  body .page.discover { padding-top: 10px; }

  /* ---- bottom nav (fixed, safe area) ------------------------------------------------------ */
  body .web-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; box-sizing: border-box;
    align-items: stretch; justify-content: space-around; gap: 2px;
    min-height: calc(var(--kwd-nav-h) + var(--kwd-safe-b));
    padding: 4px max(4px, var(--kwd-safe-r)) calc(4px + var(--kwd-safe-b)) max(4px, var(--kwd-safe-l));
    background: var(--kwd-bg, #121615); border-top: 1px solid var(--kwd-border, #343E37);
  }
  body .web-nav a, body .web-nav button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; flex: 1 1 0; position: relative;
    min-height: 44px; min-width: 64px; padding: 2px 4px; background: none; border: 0; border-radius: 10px;
    color: var(--kwd-muted, #B6C0B8); font-size: 10px; font-weight: 650; line-height: 1.2; text-decoration: none; white-space: nowrap;
  }
  body .web-nav a.sel, body .web-nav button.sel, body .web-nav [aria-current=page] { color: var(--kwd-lime, #D4FF3A); }
  body .web-nav .count {
    position: absolute; top: 2px; right: calc(50% - 24px); background: var(--kwd-lime, #D4FF3A); color: #111B10;
    border-radius: 10px; padding: 0 5px; font-size: 9px; font-weight: 800; line-height: 14px;
  }
  body .web-nav [hidden] { display: none; }   /* e.g. My Dining until Session Two's page exists */
  /* The site footer sits below <main>: give it room above the fixed nav, and drop it from the swipe view
     (nothing may scroll under the deck there; its links stay on Home and Saved). */
  body .kwd-foot { padding-bottom: calc(22px + var(--kwd-nav-h) + var(--kwd-safe-b)); }
  body:has(.kwd-foot) .page:not(.focus-page) { padding-bottom: 16px; }
  body.swipe-focus .kwd-foot, body:has(.page.focus-page) .kwd-foot { display: none; }

  /* ---- actions strip (fixed above the nav, only in swipe view) ---------------------------- */
  body .phone-actions {
    position: fixed; left: 0; right: 0; bottom: calc(var(--kwd-nav-h) + var(--kwd-safe-b)); z-index: 19; box-sizing: border-box;
    height: var(--kwd-actions-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 2px max(6px, var(--kwd-safe-r)) 2px max(6px, var(--kwd-safe-l));
    background: var(--kwd-bg, #121615); border-top: 1px solid var(--kwd-border, #343E37);
  }
  body .phone-actions:empty { display: none; }
  body .phone-actions .actions { width: 100%; padding: 0; gap: 18px; justify-content: center; align-items: flex-start; }
  body .phone-actions .gesturehint { font-size: 9px; margin: 1px 0 0; color: var(--kwd-quiet, #8B9990); }
  body .actions .action-item { min-width: 48px; min-height: 44px; gap: 2px; padding: 0 2px; font-size: 10px; border-radius: 12px; }
  body .actions .action-circle { width: 46px; height: 46px; }
  body .actions .action-item.save .action-circle { width: 52px; height: 52px; }
  body .actions .action-item.undo .action-circle, body .actions .action-item.info .action-circle { width: 40px; height: 40px; margin-top: 4px; }

  /* ---- swipe view: a flex column that fills the viewport under the header ----------------- */
  /* The reference styles this element as `.swipe-focus .page.focus-page` (3 classes), so the
     `.swipe-focus` variants are listed to outrank it whether that class sits on body or a wrapper. */
  body .page.focus-page, body.swipe-focus .page.focus-page, body .swipe-focus .page.focus-page {
    display: flex; flex-direction: column; gap: 0; box-sizing: border-box; width: 100%; max-width: none; margin: 0;
    padding: 6px max(var(--kwd-gutter), var(--kwd-safe-r)) calc(4px + var(--kwd-actions-h) + var(--kwd-nav-h) + var(--kwd-safe-b)) max(var(--kwd-gutter), var(--kwd-safe-l));
    min-height: calc(100vh - var(--kwd-phone-header-h));
  }
  @supports (height: 100dvh) {
    body .page.focus-page, body.swipe-focus .page.focus-page, body .swipe-focus .page.focus-page { min-height: calc(100dvh - var(--kwd-phone-header-h)); }
  }

  body .page.focus-page .focus-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px; margin: 0 0 4px; flex: none; }
  body .page.focus-page .focus-toolbar .focus-search { min-height: 44px; max-width: none; padding: 8px 12px; font-size: 13px; border-radius: 12px; }
  body .page.focus-page .focus-toolbar .focus-location { display: none; }   /* location lives in the search sheet on phones (reference) */
  body .page.focus-page .focus-toolbar .view-toggle { margin-left: 0; padding: 2px; min-height: 44px; box-sizing: border-box; }
  body .page.focus-page .focus-toolbar .view-toggle button { min-height: 40px; padding: 5px 9px; font-size: 11px; gap: 4px; }
  body .page.focus-page .focus-toolbar .view-toggle button svg { width: 13px; height: 13px; }
  /* Very narrow phones (≤360px): inactive view buttons show their icon only; the label stays in the
     accessibility tree (clipped, not display:none) so the buttons keep their names. */
  @media (max-width: 360px) {
    body .page.focus-page .focus-toolbar .view-toggle button:not(.on):not([aria-pressed="true"]) span {
      position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
    }
    body .page.focus-page .focus-toolbar .view-toggle button { position: relative; padding: 5px 10px; min-width: 44px; justify-content: center; }
    body .page.focus-page .focus-toolbar .view-toggle button svg { width: 15px; height: 15px; }
  }

  body .page .quickrail, body .page.focus-page .quickrail {
    flex: none; display: flex; align-items: center; gap: 6px; overflow-x: auto; overflow-y: hidden;
    margin: 0 calc(-1 * max(var(--kwd-gutter), var(--kwd-safe-r))) 0 calc(-1 * max(var(--kwd-gutter), var(--kwd-safe-l)));
    padding: 0 max(var(--kwd-gutter), var(--kwd-safe-r)) 4px max(var(--kwd-gutter), var(--kwd-safe-l));
    scrollbar-width: none; -ms-overflow-style: none; scroll-snap-type: x proximity; scroll-padding-inline: var(--kwd-gutter);
    touch-action: pan-x; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  }
  body .page .quickrail::-webkit-scrollbar { display: none; }
  body .page .quickrail .chip { flex: none; min-height: 44px; padding: 8px 12px; font-size: 12px; scroll-snap-align: start; }
  body .page .quickrail .chip svg { width: 14px; height: 14px; }

  body .page.focus-page .workspace { display: flex; flex-direction: column; flex: 1; min-height: 0; gap: 0; align-items: stretch; }
  body .page .workspace .filter-rail, body .page .workspace .right-rail { display: none; }
  body .page .workspace.list-mode, body .page .workspace.map-mode { display: block; }
  body .page.focus-page .focus-deck { display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%; min-width: 0; }
  body .page.focus-page .deck-top { flex: none; margin: 0 0 2px; max-width: none; width: 100%; }
  body .page.focus-page .deck-top h2 { font-size: 13px; }
  body .page.focus-page .deck-top .deck-sub { font-size: 10px; }
  body .page.focus-page .deck-top .small { font-size: 11px; }

  body .page.focus-page .deck { position: relative; display: flex; flex: 1; min-height: 244px; width: 100%; max-width: none; margin: 0; padding: 0 0 4px; }
  body .page.focus-page .deck > *:not(.card-back) { width: 100%; min-width: 0; }
  body .page.focus-page .card-back { inset: 4px 8px 14px 6px; }
  body .page.focus-page .swipe-card { display: flex; flex-direction: column; min-height: 0; width: 100%; border-radius: 17px; }
  body .page.focus-page .photo-area { flex: 1 1 0; min-height: 190px; height: auto; max-height: none; width: 100%; }
  /* Absolute media never adds to the photo area's height, so the flex sizing stays exact. */
  body .page.focus-page .photo-area > img, body .page.focus-page .photo-area > video, body .page.focus-page .photo-area > picture, body .page.focus-page .photo-area > .empty-img {
    position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center;
  }
  body .page.focus-page .photo-area > picture img { width: 100%; height: 100%; object-fit: cover; }
  body .page.focus-page .card-copy { left: 12px; right: 12px; bottom: 10px; }
  body .page.focus-page .card-copy h2 { font-size: clamp(22px, 7vw, 28px); }
  body .page.focus-page .card-copy .line { font-size: 12px; }
  body .page.focus-page .card-copy .tags { margin-top: 6px; }
  body .page.focus-page .card-copy .tag { font-size: 10px; padding: 3px 7px; }
  body .page.focus-page .photo-attribution { top: 22px; left: 12px; }
  body .page.focus-page .photo-attribution .tag { font-size: 10px; }
  body .page.focus-page .photo-count { top: 22px; right: 12px; }
  body .page.focus-page .photo-nav { width: 44px; height: 48px; top: 46%; }
  body .page.focus-page .photo-nav.prev { left: 6px; }
  body .page.focus-page .photo-nav.next { right: 6px; }
  body .page.focus-page .decision { font-size: 24px; top: 16%; }
  body .page.focus-page .card-info {
    flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; box-sizing: border-box;
    min-height: 48px; padding: 3px 6px 3px 12px;
  }
  body .page.focus-page .card-info .photo-caption { flex: 1; min-width: 0; }
  body .page.focus-page .card-info .headline { font-size: 12px; margin: 0 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body .page.focus-page .card-info .meta { font-size: 10px; gap: 8px; flex-wrap: nowrap; white-space: nowrap; overflow: hidden; }
  body .page.focus-page .card-info .meta > * { min-width: 0; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body .page.focus-page .details-link {
    display: inline-flex; align-items: center; flex: none; width: auto; min-height: 44px; min-width: 44px;
    padding: 4px 6px; font-size: 12px; gap: 4px; white-space: nowrap; border-radius: 10px; text-decoration: none;
  }
  body .page.focus-page .focus-deck > .empty, body .page.focus-page .deck > .empty { width: 100%; margin: auto 0; align-self: center; padding: 24px 14px; }
  body .page.focus-page .empty h2 { font-size: 20px; }
  body .page.focus-page .empty .btn { width: 100%; }
  /* Short screens (320×568, landscape): the photo is near its minimum, so the copy keeps to name + line
     and the photo arrows sit above it. */
  @media (max-height: 640px) {
    body .page.focus-page .card-copy .tags { display: none; }
    body .page.focus-page .card-copy h2 { font-size: 22px; }
    body .page.focus-page .photo-nav { top: 38%; }
  }

  /* ---- discover head (list / map layout) -------------------------------------------------- */
  body .discover-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin: 0 0 10px; }
  body .discover-head h1 { font-size: 22px; }
  body .discover-head .eyebrow { display: none; }
  body .discover-head .searchline { grid-column: 1 / -1; width: 100%; max-width: none; order: 3; padding: 3px 4px 3px 10px; }
  body .discover-head .searchline input { min-height: 38px; }
  body .discover-head .searchline .btn { min-height: 40px; }
  body .discover-head .view-toggle { justify-self: end; padding: 2px; }
  body .discover-head .view-toggle button { font-size: 11px; padding: 5px 9px; min-height: 40px; }
  body .mobile-location { display: inline-flex; min-height: 44px; }

  /* ---- list ------------------------------------------------------------------------------- */
  body .list-grid, body .list-mode .list-grid { grid-template-columns: 1fr; gap: 10px; }
  body .listing { display: grid; grid-template-columns: 112px minmax(0, 1fr); }
  body .listing .pic { height: 100%; min-height: 140px; }
  body .listing .pic .iconbtn { width: 40px; height: 40px; }
  body .listing .info { padding: 10px 10px 10px 12px; }
  body .listing h3 { white-space: normal; font-size: 16px; }
  body .listing .info .btn { min-height: 44px; }
  body .list-head h2 { font-size: 19px; }

  /* ---- map -------------------------------------------------------------------------------- */
  body .map-wrap { display: flex; flex-direction: column; gap: 10px; }
  body .map, body #kwd-map { width: 100%; height: clamp(260px, calc(100vh - 360px), 440px); }
  @supports (height: 100dvh) { body .map, body #kwd-map { height: clamp(260px, calc(100dvh - 360px), 440px); } }
  body .map-preview { width: 100%; display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; align-items: center; padding: 10px; }
  body .map-preview img { height: 110px; border-radius: 10px; }
  body .map-preview h3 { margin: 0 0 4px; font-size: 17px; }
  body .map-preview .btn { margin-top: 8px; min-height: 44px; padding: 7px 10px; }
  body .map-label { max-width: min(220px, 60%); }
  body .map-pin { min-width: 44px; min-height: 44px; }
  body .map-tools .iconbtn { width: 44px; height: 44px; }

  /* ---- saved ------------------------------------------------------------------------------ */
  body .saved-grid { grid-template-columns: 1fr; gap: 10px; }
  body .saved-card .pic { height: 170px; }
  body .saved-head { align-items: flex-start; gap: 10px; }
  body .saved-head h1, body .my-head h1 { font-size: 27px; }
  body .saved-head .btn { font-size: 12px; padding: 8px 10px; }
  body .saved-card .info .btn { min-height: 44px; }

  /* ---- home ------------------------------------------------------------------------------- */
  body .home-hero { display: flex; flex-direction: column; min-height: 0; }
  body .home-copy { padding: 22px 16px; gap: 12px; }
  body .home-copy h1 { font-size: clamp(30px, 9vw, 38px); }
  body .home-copy p { font-size: 14px; }
  body .home-search input { min-height: 44px; }
  body .hero-photo { height: 190px; min-height: 190px; }
  body .hero-label h2 { font-size: 22px; }
  body .cat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 12px 0 20px; }
  body .category .category-pic { height: 100px; }
  body .category span { padding: 10px; font-size: 12px; min-height: 44px; align-items: center; }
  body .home-shortcuts { grid-template-columns: 1fr; gap: 10px; }
  body .home-shortcuts button, body .home-shortcuts a { padding: 14px; min-height: 44px; }
  body .home-shortcuts h3 { margin: 6px 0 2px; font-size: 16px; }
  body .section-title { margin: 18px 0 8px; }
  body .section-title h2 { font-size: 20px; }

  /* ---- dialogs become bottom sheets; the search sheet hangs from the top (keyboard) -------- */
  body .overlay { position: fixed; inset: 0; z-index: 50; padding: 0; align-items: flex-end; justify-content: center; height: 100vh; }
  @supports (height: 100dvh) { body .overlay { height: 100dvh; } }
  body .dialog {
    width: 100%; max-width: none; height: auto; max-height: 96%; border-radius: 20px 20px 0 0; border-bottom: 0;
    animation: kwd-sheet-up .2s ease-out;
  }
  body .dialog.filter-dialog { height: 94%; max-height: 94%; }
  body .dialog-header { padding: 10px 12px 10px 14px; min-height: 56px; }
  body .dialog-header h2 { font-size: 19px; }
  body .dialog-header .iconbtn { width: 44px; height: 44px; }
  body .dialog-body { padding: 14px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  body .dialog-footer { padding: 10px 14px calc(10px + var(--kwd-safe-b)); gap: 8px; }
  body .dialog-footer .btn { min-height: 48px; }
  body .dialog .filter-choices .chip { min-height: 44px; font-size: 13px; padding: 8px 12px; }
  body .dialog .filter-group select { min-height: 44px; }
  body .dialog .switchrow { min-height: 44px; }
  body .dialog input[type=checkbox] { width: 22px; height: 22px; }
  body .overlay:has(.search-dialog) { align-items: flex-start; }
  body .dialog.search-dialog {
    border-radius: 0 0 20px 20px; border-top: 0; border-bottom: 1px solid var(--kwd-border, #343E37);
    padding-top: var(--kwd-safe-t); max-height: min(96%, 440px); animation-name: kwd-sheet-down;
  }
  body .search-dialog .dialog-body { padding-bottom: 18px; }
  body .search-dialog .searchline { max-width: none; padding: 4px 4px 4px 12px; }
  body .search-dialog .searchline input { min-height: 44px; }
  body .search-dialog .searchline .btn { min-height: 44px; }

  /* ---- toast above the fixed bars --------------------------------------------------------- */
  body .toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--kwd-nav-h) + var(--kwd-safe-b) + 12px); max-width: calc(100% - 24px); z-index: 60; }
  body:has(.phone-actions:not(:empty)) .toast { bottom: calc(var(--kwd-actions-h) + var(--kwd-nav-h) + var(--kwd-safe-b) + 12px); }
}

/* ---- landscape phones (e.g. 844×390): quick chips across the top, card left, search + view
        toggle in a right column with the actions strip pinned under them; nav 44px. ----------- */
@media (max-width: 1024px) and (max-height: 520px) and (orientation: landscape) {
  :root { --kwd-phone-header-h: 44px; --kwd-nav-h: 44px; }
  body .header, .swipe-focus .header, body.swipe-focus .header { height: 44px; min-height: 44px; }
  body .header .logo img, body .header .logo svg { height: 20px; }
  body .web-nav { padding-top: 0; padding-bottom: var(--kwd-safe-b); }
  body .web-nav a, body .web-nav button { flex-direction: row; gap: 6px; min-height: 44px; font-size: 11px; }
  body .web-nav .count { position: static; margin-left: 2px; }
  body .page.focus-page, body.swipe-focus .page.focus-page, body .swipe-focus .page.focus-page {
    display: grid; grid-template-columns: minmax(0, 1fr) 236px; grid-template-rows: auto minmax(0, 1fr); column-gap: 10px; row-gap: 0;
    padding: 4px max(var(--kwd-gutter), var(--kwd-safe-r)) calc(4px + var(--kwd-nav-h) + var(--kwd-safe-b)) max(var(--kwd-gutter), var(--kwd-safe-l));
  }
  body .page.focus-page .quickrail { grid-column: 1 / -1; grid-row: 1; padding-bottom: 4px; }
  body .page.focus-page .quickrail .chip { min-height: 44px; padding: 6px 10px; }
  body .page.focus-page .focus-toolbar { grid-column: 2; grid-row: 2; display: flex; flex-direction: column; align-items: stretch; gap: 6px; margin: 0; align-self: start; }
  body .page.focus-page .focus-toolbar .view-toggle { width: 100%; display: flex; }
  body .page.focus-page .focus-toolbar .view-toggle button { flex: 1; }
  body .page.focus-page .workspace { grid-column: 1; grid-row: 2; min-height: 0; }
  body .page.focus-page .deck { min-height: 170px; }
  body .page.focus-page .photo-area { min-height: 150px; }
  body .page.focus-page .card-copy h2 { font-size: 22px; }
  body .page.focus-page .focus-deck > .empty, body .page.focus-page .deck > .empty { padding: 14px; }
  body .phone-actions {
    left: auto; right: 0; width: calc(236px + var(--kwd-gutter) + var(--kwd-safe-r)); border-top: 0;
    padding-left: 4px; padding-right: max(4px, var(--kwd-safe-r));
  }
  body .phone-actions .actions { gap: 10px; }
  body .phone-actions .gesturehint { display: none; }
  body .map, body #kwd-map { height: clamp(200px, calc(100vh - 150px), 300px); }
  @supports (height: 100dvh) { body .map, body #kwd-map { height: clamp(200px, calc(100dvh - 150px), 300px); } }
}

@keyframes kwd-sheet-up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes kwd-sheet-down { from { transform: translateY(-24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .dialog, .dialog.search-dialog { animation: none; }
  .quickrail { scroll-behavior: auto; scroll-snap-type: none; }
}
