/* OrderTech ERP demo: mobile polish (phones up to 760px).
   Loaded after app.css with media="(max-width: 760px)", and every rule below also sits inside the
   same media query, so desktop and tablet layouts are untouched. Only existing tokens are used.
   Principles: two-row shell header (164px incl. the 44px return bar), 44px touch targets,
   16px form text (no iOS zoom), bottom sheets for dialogs, readable cards and whole amounts. */

@media (max-width: 760px) {
  :root { --bar-h: 164px; }

  /* ---------- shell header: row 1 brand + languages, row 2 role picker + tutorial ---------- */
  .bar {
    height: 120px;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: repeat(2, minmax(0, 1fr));
    grid-template-areas: "brand lang" "pick tour";
    align-content: center;
    column-gap: 8px;
    row-gap: 4px;
    padding-block: 6px;
  }
  .bar-tools { display: contents; }
  .bar .brand { grid-area: brand; gap: 8px; align-self: center; min-width: 0; min-height: 44px; }
  .bar .brand img { width: 30px; }
  .bar .brand-t { display: grid; min-width: 0; }
  .bar .brand-t small { display: none; }
  .bar .brand-row { min-width: 0; }
  .bar .brand-t b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bar .lang-seg { grid-area: lang; align-self: center; }
  .bar .lang-seg button { min-width: 44px; height: 44px; padding: 0; font-size: 14px; }
  .bar .role-pick { grid-area: pick; align-self: center; width: 100%; max-width: none; height: 48px; }
  .bar .tb-tour { grid-area: tour; align-self: center; width: auto; height: 48px; max-width: min(46vw, 200px); min-width: 48px; padding: 0 14px; gap: 6px; border-radius: 11px; font-size: 13.5px; }
  .bar .tb-tour span { display: inline; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  /* Guide, States and Reset stay one tap away in the role sheet (.sheet-tools, .mobile-sheet-reset). */
  .bar .tb-guide, .bar .tb-sim, .bar .tdiv, .bar .tb-reset { display: none; }

  /* ---------- role sheet ---------- */
  .sheet { max-height: 88dvh; overscroll-behavior: contain; }
  .sheet-h .icon-btn { width: 44px; height: 44px; }
  .sheet-tools { display: grid; }
  .mobile-sheet-reset { display: flex; margin-top: 8px; color: var(--danger); border-color: var(--danger-line); }
  .mobile-sheet-reset:hover { background: var(--danger-tint); border-color: var(--danger); }

  /* ---------- context: a one-line summary that opens the 2 x 2 facts, then the next step ---------- */
  .ctx { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding-block: 8px 10px; }
  .mobile-context-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 44px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); text-align: start; }
  .mobile-context-toggle:hover { border-color: var(--accent-line); }
  .mc-summary { display: grid; gap: 1px; min-width: 0; line-height: 1.3; }
  .mc-summary b { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mc-summary small { font-size: 12.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mobile-context-toggle .ic { flex: none; color: var(--dim); transition: transform .15s; }
  .ctx.is-expanded .mobile-context-toggle .ic { transform: rotate(180deg); }
  .ctx-facts { display: none; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; overflow: visible; }
  .ctx.is-expanded .ctx-facts { display: grid; }
  .fact, .fact:first-child { min-width: 0; min-height: 56px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); white-space: normal; }
  .fact dd { flex-wrap: wrap; row-gap: 4px; min-width: 0; }
  .fact-link { flex-wrap: wrap; gap: 4px 6px; min-height: 44px; text-align: start; }
  .ctx-next { width: 100%; min-height: 64px; padding-block: 8px; padding-inline: 12px 8px; gap: 10px; }
  .cn-hint { font-size: 14px; }
  .cn-go { height: 44px; min-width: 44px; padding: 0 12px; justify-content: center; }
  .ctx-tour, .ctx-done { width: 100%; min-height: 44px; }
  .ctx-tour { justify-content: center; }

  /* ---------- touch targets and form text ---------- */
  #app :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea) { font-size: 16px; }
  .btn, .btn-sm, .go, .seg button, .seg-o button, .obtn, .obtn-sm, .pbtn, .pbtn-sm, .sf-btn, .sf-btn-sm,
  .sf-method button, .sf-cats button, .chip-opt, .ai-sugg button, .sai-sugg button, .pos-filter button,
  .voice-bar .sf-btn, .icon-btn { min-height: 44px; }
  .icon-btn, .tb-x { min-width: 44px; width: 44px; height: 44px; }
  .sim-row { min-height: 44px; }
  .sim-row input { width: 22px; height: 22px; }
  .qr-spec summary, .cost-cons summary { min-height: 44px; }
  .qty button, .qty-sm button { width: 44px; height: 44px; }
  .sf-add { width: 44px; height: 44px; }
  .sf-branch select, .pos-branch select, .kds-branch select, .erp-tabsel select, .pn-field select, .pn-field input { min-height: 44px; }
  .price-edit input { width: 100px; min-height: 44px; }
  .switch { position: relative; }
  .switch::before { content: ""; position: absolute; inset: -7px -4px; } /* 30px switch, 44px hit area */
  .pn-type .seg-o button, .pn-search input, .sf-back, .lnk, .lnk-plain { min-height: 44px; }
  .sf-brand { min-height: 44px; }
  .sf-x { width: 44px; height: 44px; }
  .go { min-width: 44px; }
  .lnk-small { display: inline-flex; align-items: center; min-height: 44px; }
  /* Screen-reader labels (.sr is position:absolute) inside a horizontal scroller used to escape it and
     widen the page (inventory cost edit: "New cost" label at x=381 on a 320px screen). */
  .tbl-scroll { position: relative; }

  /* ---------- dialogs become bottom sheets ---------- */
  .drawer { top: auto; bottom: 0; inset-inline: 0; width: auto; max-height: min(82dvh, calc(100dvh - var(--bar-h) - 12px)); border-radius: 18px 18px 0 0; border-inline: 0; border-bottom: 0; padding: 14px max(16px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); overscroll-behavior: contain; box-shadow: 0 -18px 50px -20px rgba(23, 21, 31, .45); }
  .confirm { max-height: calc(100dvh - 32px); overflow: auto; }
  .confirm .row-end .btn { flex: 1 1 0; }
  .tour-pick { top: auto; bottom: 0; left: 0; transform: none; width: 100%; max-height: 92dvh; border-radius: 20px 20px 0 0; padding: 18px max(16px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); overscroll-behavior: contain; }
  .tour-pick h2 { font-size: 20px; padding-inline-end: 48px; }
  .tp-x { inset-block-start: 8px; inset-inline-end: 8px; }
  .tp-card { padding: 12px 14px; }
  .tb-actions .btn, .tour-bubble .btn { min-height: 44px; }
  .sai, [dir="rtl"] .sai { inset: auto 0 0 0; width: 100%; height: min(86dvh, calc(100dvh - var(--bar-h))); border-radius: 20px 20px 0 0; border-inline-start: 0; box-shadow: 0 -18px 50px -20px rgba(23, 21, 31, .45); overflow: hidden; }
  /* The customer assistant (z 35) slid under the sticky shell header (z 40/41) and its own header was
     hidden; as an overlay it now sits above the shell like the other sheets. */
  .ai-panel, .phone .ai-panel { z-index: 45; }

  /* On-screen keyboard (root sets --phone-view-height / --phone-view-bottom from VisualViewport):
     overlays stay inside the visible area and bottom panels sit on top of the keyboard. */
  .sf-sheet, .sf-drawer, .ai-panel, .sai, .sheet, .confirm, .payscr { max-height: min(92dvh, calc(var(--phone-view-height, 100dvh) - 16px)); }
  .drawer { max-height: min(82dvh, calc(var(--phone-view-height, 100dvh) - var(--bar-h) - 12px)); }
  .sf-sheet, .sf-drawer, .ai-panel, .sai, [dir="rtl"] .sai, .sheet, .drawer { bottom: var(--phone-view-bottom, 0px); }
  .ai-panel, .phone .ai-panel { height: min(86dvh, calc(var(--phone-view-height, 100dvh) - 16px)); }
  .phone-keyboard-open .pd-media { display: none; }

  /* ---------- ecosystem map: journeys first, then roles as a vertical list; no wide SVG ---------- */
  .map-wrap { gap: 18px; padding-top: 18px; }
  .map-wrap > * { order: 3; }
  .map-wrap > .map-head { order: 0; gap: 12px; }
  .map-wrap > .journeys { order: 1; gap: 12px; }
  .map-wrap > .mobile-map { order: 2; }
  .eco-scroll, .legend { display: none; }
  .lede { font-size: 15px; }
  /* Map and spec open straight on content: the shared facts only matter inside a journey. */
  .v-map .ctx, .v-spec .ctx { display: none; }
  .map-head .lede { display: none; }
  .mobile-intro { display: block; font-size: 15px; line-height: 1.7; color: var(--dim); }
  .jcard { padding: 16px; gap: 8px; }
  .jcard h2 { font-size: 19px; }
  .jcard .btn { justify-self: stretch; min-height: 48px; }
  .mobile-map { display: grid; gap: 12px; }
  .mobile-map-h { font-family: var(--f-display); font-size: 20px; font-weight: 800; }
  .mobile-map-groups { display: grid; gap: 16px; }
  .mobile-map-group { display: grid; gap: 8px; }
  .mobile-map-group h3 { font-size: 12px; font-weight: 700; color: var(--dim); letter-spacing: .06em; text-transform: uppercase; }
  :lang(ar) .mobile-map-group h3 { letter-spacing: 0; text-transform: none; }
  .mobile-map-links { display: grid; gap: 8px; }
  .mobile-map-link { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); text-align: start; }
  .mobile-map-link:hover, .mobile-map-link:active { border-color: var(--accent); background: var(--accent-tint); }
  .mobile-map-link .ic { width: 18px; height: 18px; color: var(--faint); }
  .mobile-map-link > .ic:first-child { width: 40px; height: 40px; padding: 10px; border-radius: 12px; background: var(--accent-tint); color: var(--brand); }
  .mobile-map-link-text { display: grid; gap: 2px; min-width: 0; }
  .mobile-map-link-text b { font-size: 15px; line-height: 1.3; }
  .mobile-map-link-text small { font-size: 12.5px; color: var(--dim); line-height: 1.35; }

  /* ---------- spec ---------- */
  .spec { gap: 16px; padding-top: 18px; }
  .spec-sec { padding: 16px; }

  /* ---------- restaurant: header in two rows (brand + cart, then fulfilment + branch) ---------- */
  .sf-head { gap: 0 8px; padding-block: 8px; }
  .sf-head::after { content: ""; order: 1; flex-basis: 100%; height: 0; }
  .sf-brand { flex: 1 1 auto; min-width: 0; }
  .sf-brand span { min-width: 0; }
  .sf-brand b { font-size: 19px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sf-brand small { display: none; }
  .sf-head-end { margin-inline-start: 0; }
  .sf-method, .sf-branch { order: 2; margin-top: 8px; }
  .sf-method { flex: 1 1 0; min-width: 0; }
  .sf-method button { flex: 1 1 0; min-width: 0; justify-content: center; white-space: nowrap; }
  /* fulfilment and branch share row 2 (the branch used to drop to a third sticky row) */
  .sf-branch { flex: 0 1 auto; min-width: 0; max-width: 46%; }
  .sf-branch select { min-width: 0; max-width: 100%; text-overflow: ellipsis; }
  /* Store views have their own sticky header (with the cart): the demo shell header scrolls away there,
     so a scrolled 390x844 menu keeps ~110px of chrome instead of 337px. */
  .shell.v-site, .shell.v-qr, .shell.v-account { --bar-h: 0px; }
  .shell.v-site > .demo-return, .shell.v-site > .bar, .shell.v-qr > .demo-return, .shell.v-qr > .bar,
  .shell.v-account > .demo-return, .shell.v-account > .bar { position: relative; top: auto; }
  .pd-media { max-height: 34dvh; }
  .sf-tablebar, .sf-infobar { font-size: 13px; }
  .sf-body { padding-top: 14px; gap: 14px; }
  .sf-cats { scroll-padding-inline: 16px; }

  /* ---------- POS ---------- */
  .pos-nav { gap: 8px; padding-block: 8px; }
  .pos-alert { flex-wrap: wrap; }
  .pos-detail { padding: 16px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
  .pos-actions .pbtn { flex: 1 1 calc(50% - 5px); }
  .inline-confirm .pbtn { flex: 1 1 auto; }
  .pos-lines td { padding: 9px 10px; }
  .pos-lines .price, .pcard-bot .price { white-space: nowrap; }
  .track-lg { font-size: clamp(26px, 8vw, 34px); }
  .floor-grid { padding: 12px; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 120px), 1fr)); }
  .ftable { min-height: 110px; }
  .pos-overlay:has(.payscr) { place-items: end stretch; padding: 0; }
  .pos-overlay:has(.payscr) .payscr { width: 100%; max-height: 92dvh; border-radius: 20px 20px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); overscroll-behavior: contain; }
  .pay-due p { font-size: clamp(30px, 10vw, 42px); }
  .pay-methods button { min-height: 56px; }

  /* ---------- KDS ---------- */
  .kds-h { gap: 10px; }
  .kds-title b { font-size: 16px; }
  .kds-cols { gap: 10px; }
  .kcard header > b { font-size: 22px; }
  .kcard li { grid-template-columns: 34px minmax(0, 1fr); font-size: 15.5px; }
  .kcard li div { min-width: 0; overflow-wrap: anywhere; }

  /* ---------- ERP ---------- */
  .erp-nav { gap: 10px; min-height: 60px; }
  .erp-ai-btn { width: 44px; height: 44px; }
  .erp-cp { padding: 12px max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); }
  .crumb b { font-size: 16px; }
  .erp-body { gap: 14px; padding: 14px max(16px, env(safe-area-inset-right, 0px)) 32px max(16px, env(safe-area-inset-left, 0px)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; min-width: 0; }
  .kpi b { font-size: clamp(17px, 5vw, 24px); line-height: 1.2; }
  .kpi span, .kpi small { overflow-wrap: anywhere; }
  .osheet { padding: 14px; }
  .osheet h1 { font-size: 22px; }
  .statusbar span { padding: 6px 10px; font-size: 12px; }
  .erp-impact span { min-width: 0; }
  .tbl-scroll { overscroll-behavior-x: contain; }
  .olist .r { white-space: nowrap; }
  /* The recipe card's 4-column table is not in a scroller: fit it (fixed layout, amounts may wrap
     between number and JOD) instead of pushing a 320px page to 351-373px. */
  .recipe .olist { table-layout: fixed; width: 100%; font-size: 12.5px; }
  .recipe .olist th, .recipe .olist td { padding: 6px 4px; overflow-wrap: anywhere; }
  .recipe .olist th:first-child, .recipe .olist td:first-child { width: 34%; padding-inline-start: 0; }
  .recipe .olist .r { white-space: normal; }
  .recipe .olist th { font-size: 11.5px; overflow-wrap: normal; }

  /* Small phones: brand + three 44px language targets still share row 1. */
  @media (max-width: 379px) {
    .bar .demo-tag { display: none; }
    /* The current role name matters more than the tutorial label here: the tour button keeps its
       icon (48px target, named by its title) and the picker takes the rest of row 2. */
    .bar { grid-template-areas: "brand lang" "pick pick"; }
    .bar .role-pick { width: auto; justify-self: stretch; margin-inline-end: 56px; }
    .bar .tb-tour { grid-area: pick; justify-self: end; width: 48px; min-width: 48px; padding: 0; }
    .bar .tb-tour span { display: none; }
    .sf-method button .ic, .sf-branch > .ic { display: none; }
  }

  /* Small product sheets keep quantity and the full add-to-cart amount on separate rows. */
  @media (max-width: 420px) {
    .pd-foot { flex-wrap: wrap; justify-content: center; }
    .pd-foot > .qty { flex: none; }
    .pd-foot .sf-btn.grow { flex: 1 1 100%; min-width: 0; min-height: 52px; padding: 10px 12px; line-height: 1.5; }
  }

  /* Short screens: compact context strip (the store header stays sticky: it is the only chrome there). */
  @media (max-height: 640px) {
    .ctx { padding-block: 6px 8px; }
  }

  /* Very short screens (small phones in landscape): the 164px header scrolls away
     instead of covering a third of the screen; sticky offsets follow (--bar-h: 0). */
  @media (max-height: 480px) {
    :root { --bar-h: 0px; }
    .demo-return, .bar { position: relative; top: auto; }
    .sai, [dir="rtl"] .sai { height: 86dvh; }
    /* landscape phones: the store header scrolls too, and the product photo leaves room for options */
    .sf-head { position: relative; top: auto; }
    .pd-media { max-height: 30dvh; }
  }
}
