/* Dispatcher phone (Round 6 #19 #20 #21, look A – Kam, Nov 22): bottom tabs, ☰ menu sheet, ⋯ menus and windows as sheets, 44 px targets.
   Colours are look A's variables only (nothing here has a colour of its own – a test checks that). Loaded after look-a.css. Phones only (≤ 760 px). */
.pd .phone-only, .pd #phoneTabs, .pd #phoneStatus, .pd .psheet-back, .pd .pchips, .pd .mapdrv { display: none; }

/* the ☰ menu sheet – phones and tablets (≤ 1023 px; on a tablet the left menu is behind the ☰ button – public/layout.css makes the sheet a side panel there) */
@media (max-width: 1023px) {
  .pd .psheet-back { position: fixed; inset: 0; z-index: 85; background: var(--dim); align-items: flex-end; }
  .pd .psheet-back:not(.hidden) { display: flex; }
  .pd .psheet { width: 100%; max-height: 90dvh; overflow: auto; background: var(--card); border-radius: 24px 24px 0 0; box-shadow: var(--floatShadowCss); padding: 8px 16px calc(18px + env(safe-area-inset-bottom)); }
  .pd .psheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line2); margin: 4px auto 10px; }
  .pd .pm-me { display: flex; align-items: center; gap: 12px; padding: 4px 0 12px; }
  .pd .pm-me .av { width: 40px; height: 40px; border-radius: 50%; background: var(--avBg); color: var(--avText); display: grid; place-items: center; font-weight: 800; }
  .pd .pm-me b { display: block; font-size: 16px; }
  .pd .pm-me span { color: var(--ink2); font-size: 12.5px; font-weight: 600; }
  .pd .pm-me .ibtn { margin-left: auto; width: 44px; height: 44px; }
  .pd .pm-list .nl { margin: 14px 4px 4px; font-size: 12px; font-weight: 800; color: var(--ink3); letter-spacing: .04em; text-transform: uppercase; }
  .pd .pm-list button { width: 100%; min-height: 52px; display: flex; align-items: center; gap: 14px; padding: 0 10px; border: 0; background: none; border-radius: 14px; font-size: 16px; font-weight: 650; text-align: left; color: var(--ink); }
  .pd .pm-list button:active { background: var(--soft); }
  .pd .pm-list button span { flex: 1; }
  .pd .pm-list button em { font-style: normal; font-size: 13px; font-weight: 800; color: var(--ink2); background: var(--soft); border-radius: 10px; padding: 2px 9px; }
  .pd .pm-list button em:empty { display: none; }
  .pd .pm-list button.hidden { display: none; }

}

@media (max-width: 760px) {
  /* ---------- page frame ---------- */
  .pd .app { display: block; }
  .pd .side { display: none; }
  .pd .main { padding: 12px 14px calc(170px + env(safe-area-inset-bottom)); gap: 4px; } /* room under every list so the floating Paste order never covers the last card */
  .pd .phone-only { display: grid; }
  .pd .top { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 8px 8px; margin-bottom: 10px; }
  .pd .top > div:first-child { min-width: 0; }
  .pd .top > div:first-child > .row { flex-direction: column-reverse; align-items: flex-start; gap: 0; }
  .pd .top h1 { font-size: 26px; }
  .pd .top .when { font-size: 12.5px; }
  .pd .top .sum { display: none; } /* the tabs' numbers say it (Round 6 #19 has no stats line) */
  .pd .top .sp, .pd .top #holdBtn, .pd .top #soundBtn, .pd .top #activityBtn { display: none; }
  .pd .top .search { display: none; grid-column: 1 / -1; width: auto; height: 46px; position: relative; }
  body.psearch .pd .top .search { display: flex; }
  .pd .top .ibtn { width: 44px; height: 44px; border-radius: 14px; }
  .pd .top .ibtn .dot { top: -6px; right: -6px; }
  /* Paste order: one big button over the tabs (not on the map) */
  .pd .top #btnPasteOrder { position: fixed; right: 16px; bottom: calc(82px + env(safe-area-inset-bottom)); z-index: 35; height: 52px; padding: 0 20px; border-radius: 26px; font-size: 15px; }
  body[data-ptab='map'] .pd .top #btnPasteOrder { display: none; }
  body[data-page]:not([data-page='board']) .pd .top #btnPasteOrder { display: none; }
  .pd .handover-bar { margin-bottom: 8px; }

  /* the status strip the left menu's pills had (the left menu is not on a phone) */
  .pd #phoneStatus { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin: 0 0 10px; font-size: 13px; }
  .pd #phoneStatus span { display: inline-flex; gap: 6px; align-items: center; font-weight: 700; }
  .pd #phoneStatus .pwa { color: var(--late); }
  .pd #phoneStatus .pai { color: var(--wait); }
  .pd #phoneStatus small { color: var(--ink2); font-weight: 600; font-size: 12.5px; }
  .pd #phoneStatus:empty { display: none; }

  /* ---------- the four tabs: one section at a time ---------- */
  .pd #boardMain { display: block; }
  .pd #boardMain #drvCard, .pd #boardMain .col-mid, .pd #boardMain .col-right { display: none; }
  .pd #boardMain #mapCardR6, .pd #boardMain #queueCard { display: none; }
  body[data-ptab='drivers'] .pd #boardMain #drvCard { display: block; }
  body[data-ptab='orders'] .pd #boardMain .col-mid, body[data-ptab='orders'] .pd #boardMain #queueCard { display: block; }
  body[data-ptab='routes'] .pd #boardMain .col-right { display: flex; }
  body[data-ptab='map'] .pd #boardMain .col-mid, body[data-ptab='map'] .pd #boardMain #mapCardR6 { display: block; }
  body[data-ptab='map'] .pd #mapc { height: calc(100dvh - 330px); min-height: 360px; }

  /* ---------- bottom tabs ---------- */
  .pd #phoneTabs { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--card); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); box-shadow: var(--floatShadowCss); }
  .pd #phoneTabs button { position: relative; flex: 1; min-height: 56px; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11.5px; font-weight: 700; color: var(--ink3); border-radius: 14px; }
  .pd #phoneTabs button.on { color: var(--ink); }
  .pd #phoneTabs button.on .ic { color: var(--accent2); stroke-width: 2.3; }
  .pd #phoneTabs button.on::before { content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
  .pd #phoneTabs .pbadge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: var(--accent2); color: var(--onAccent); font-style: normal; font-size: 11px; font-weight: 800; display: grid; place-items: center; border: 2px solid var(--card); }
  .pd #phoneTabs .pbadge.hidden { display: none; }

  /* ---------- ⋯ menus become sheets ---------- */
  .pd .menu { position: fixed !important; left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important; width: auto !important; max-width: none !important; min-width: 0 !important; max-height: 78dvh; overflow: auto; border-radius: 24px 24px 0 0; padding: 14px 14px calc(16px + env(safe-area-inset-bottom)); z-index: 90; box-shadow: var(--floatShadowCss); }
  /* the dim is a huge shadow around the sheet (so tapping it is a tap outside the menu, which closes it) */
  .pd .menu { box-shadow: 0 0 0 100vmax var(--dim), var(--floatShadowCss); }
  .pd:has(.menu:not(.hidden)) #phoneTabs, .pd:has(.menu:not(.hidden)) .top #btnPasteOrder { display: none; }
  .pd .menu .mi { min-height: 50px; font-size: 16px; border-radius: 14px; }
  .pd .rc.open-menu { z-index: auto; }
  .pd .qrow .menu, .pd .rc .menu { z-index: 90; }
  .pd .rc.open-menu, .pd .qrow:has(> .menu) { animation: none !important; transform: none !important; } /* a transform would make the sheet relative to the card instead of the screen */

  /* ---------- windows (Edit order, Assign, Add stop, driver panel, Check in, Add a done order …) ---------- */
  .pd .r6dim { padding: 0; align-items: flex-end; justify-content: stretch; }
  .pd .r6dim .r6modal { width: 100% !important; max-width: none !important; margin: 0; max-height: 92dvh; overflow: auto; border-radius: 24px 24px 0 0; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .pd .r6dim.side { padding: 0; align-items: flex-end; background: var(--dim); pointer-events: auto; }
  .pd .r6dim.side .r6modal { max-height: 88dvh; }
  .pd .r6modal .inp, .pd .r6modal select, .pd .r6modal .btn { min-height: 46px; font-size: 16px; }
  .pd .r6modal .eo-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .pd .r6modal .eo-grid > *, .pd .r6modal [style*="grid-column"] { grid-column: 1 / -1 !important; min-width: 0; } /* fields that spanned two columns would make a second one */
  .pd .r6modal .grid2, .pd .r6modal .grid3, .pd .r6modal [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  /* the Order desk and the old windows (.lg) as bottom sheets too */
  .lg .modal-back { padding: 0; place-items: end center; }
  .lg .modal-back .modal { width: 100%; max-width: none; border-radius: 24px 24px 0 0; max-height: 92dvh; overflow: auto; }
  .lg .modal-back.ask { place-items: end center; }
  .pd #deskPanel.open, .lg #deskPanel.open { position: fixed !important; left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important; width: 100% !important; max-width: none !important; max-height: 92dvh; margin: 0; border-radius: 24px 24px 0 0; overflow: auto; z-index: 90; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }

  /* ---------- nothing may be wider than the screen ---------- */
  html, body { overflow-x: hidden; max-width: 100vw; }
  .pd .main, .pd #boardMain, .pd .card { max-width: 100%; min-width: 0; }
  .pd .ch { flex-wrap: wrap; row-gap: 2px; }
  .pd .ch .meta { flex-basis: 100%; white-space: normal; }
  .pd .qrow { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 10px; padding: 14px 14px; }
  .pd .qrow > :nth-child(1) { grid-column: 1; grid-row: 1; }
  .pd .qrow > :nth-child(3) { grid-column: 2; grid-row: 1; display: flex; flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
  .pd .qrow > :nth-child(2) { grid-column: 1 / -1; grid-row: 2; min-width: 0; }
  .pd .qrow .sug { flex-wrap: wrap; }

  /* map switch chips and the Order desk's buttons wrap / scroll instead of running off the screen */
  .pd .mapseg { max-width: calc(100% - 76px); overflow-x: auto; scrollbar-width: none; }
  .pd .mapseg button { flex: none; }
  .lg #deskPanel .row { flex-wrap: wrap; }
  .lg #deskPanel .row .btn { flex: 1 1 auto; }
  .pd table.ord tr.orw > td:nth-child(4) { text-align: left; }

  /* ---------- cards on a phone ---------- */
  .pd .card { border-radius: 20px; }
  .pd .dr, .pd .qrow, .pd .rc .rs { min-height: 56px; }
  .pd .btn, .pd .btn.sm { min-height: 44px; }
  .pd .chip, .pd .tab { min-height: 40px; }
  .pd .rc .acts { flex-wrap: wrap; }
  .pd .ordpage { grid-template-columns: 1fr; }
  /* the Orders table becomes one card per row */
  .pd table.ord, .pd table.ord tbody { display: block; width: 100%; }
  .pd table.ord thead { display: none; }
  .pd table.ord tr.orw { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 12px 14px; border-top: 1px solid var(--line); }
  .pd table.ord tr.orw > td { display: block; padding: 0; border: 0; min-width: 0; }
  .pd table.ord tr.orw > td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .pd table.ord tr.orw > td:nth-child(2) { grid-column: 2; grid-row: 1; }
  .pd table.ord tr.orw > td:last-child { grid-column: 3; grid-row: 1; text-align: right; }
  .pd table.ord tr.orw > td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; }
  .pd table.ord tr.orw > td:nth-child(4)::before { content: "Boxes "; color: var(--ink3); font-weight: 600; }
  .pd table.ord tr.orw > td:nth-child(4) { grid-column: 1 / 3; grid-row: 3; font-weight: 700; }
  .pd table.ord tr.orw > td:nth-child(5) { grid-column: 3; grid-row: 3; text-align: right; font-weight: 600; }
  .pd table.ord tr.orw > td:nth-child(n+6):not(:last-child) { grid-column: 1 / -1; font-size: 13px; color: var(--ink2); }
  .pd table.ord tr.orw > td:empty { display: none; }
  .lg #toasts, .lg .undo-bar { bottom: calc(150px + env(safe-area-inset-bottom)); }

  /* ---------- Drivers tab: Round 6's chips and the compact list (no "Driver queue" box) ---------- */
  .pd #drvCard { background: none; border: 0; box-shadow: none; padding: 0; overflow: visible; }
  .pd #drvCard > .ch { display: none; }
  .pd .pchips { display: flex; gap: 8px; align-items: center; margin: 2px 0 12px; overflow-x: auto; scrollbar-width: none; }
  .pd .pchips .sp { flex: 1; }
  .pd .pchip { flex: none; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1.5px solid var(--line2); background: var(--card); color: var(--ink); font-size: 15px; font-weight: 700; display: inline-flex; align-items: center; gap: 7px; }
  .pd .pchip b { color: var(--ink3); font-weight: 700; }
  .pd .pchip.on { background: var(--navy); color: var(--onNavy); border-color: var(--navy); }
  .pd .pchip.on b { color: inherit; opacity: .8; }
  .pd .pchips .pcheckin { flex: none; width: 46px; height: 46px; min-height: 46px; padding: 0; border-radius: 50%; justify-content: center; }
  .pd .pchips .pcheckin span { display: none; }
  .pd .pchips .pcheckin .ic { width: 22px; height: 22px; }
  .pd .drvlist { background: var(--card); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; box-shadow: var(--cardShadowCss); }
  .pd .drvlist .empty { padding: 18px 16px; color: var(--ink2); }

  /* ---------- Orders tab: one tidy card per order ---------- */
  .pd .qrow > :nth-child(3) { flex-direction: row !important; flex-wrap: nowrap; align-items: center !important; justify-content: flex-end; gap: 8px; }
  .pd .qrow > :nth-child(3) .more { width: 44px; height: 38px; }
  .pd .qrow .sug { display: flex; flex-wrap: nowrap; align-items: center; gap: 10px; padding: 10px 12px; }
  .pd .qrow .sug .sp { display: none; }
  .pd .qrow .sug > :not(.btn):not(svg):not(.ic) { flex: 1; min-width: 0; white-space: normal; }
  .pd .qrow .sug .btn { flex: none; min-height: 44px; }

  /* ---------- the ⋯ sheet scrolls, and every item can be reached ---------- */
  .pd .menu { overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
  .pd .menu .mi { min-height: 46px; }

  /* ---------- Map tab: the whole screen, the title floats over it, the drivers float at the bottom (Round 6 #19) ---------- */
  body.pmap .pd .main { padding: 0; }
  body.pmap .pd .top { position: fixed; top: 10px; left: 10px; right: 10px; z-index: 36; margin: 0; padding: 8px 8px 8px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--floatShadowCss); }
  body.pmap .pd #phoneStatus { display: none; }
  body.pmap .pd #mapCardR6 { position: fixed; left: 0; right: 0; top: 0; bottom: calc(68px + env(safe-area-inset-bottom)); z-index: 20; border: 0; border-radius: 0; box-shadow: none; }
  body.pmap .pd #mapCardR6 > .ch { position: absolute; top: 96px; left: 12px; right: 70px; z-index: 6; padding: 6px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--cardShadowCss); width: fit-content; max-width: calc(100% - 82px); }
  body.pmap .pd #mapCardR6 > .ch h2, body.pmap .pd #mapCardR6 > .ch .sp, body.pmap .pd #mapCardR6 > .ch .lnk { display: none; }
  body.pmap .pd #mapc { height: 100% !important; min-height: 0; border-radius: 0; }
  body.pmap .pd .mapseg { top: 142px; left: 12px; max-width: calc(100% - 82px); }
  body.pmap .pd .mapctl { top: 96px; right: 12px; z-index: 6; }
  body.pmap .pd .mapctl button { width: 46px; height: 46px; border-radius: 14px; }
  body.pmap .pd #mapc .legend, body.pmap .pd #mapc #mapPinKey { display: none; }
  body.pmap .pd .mapdrv { display: block; position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 6; max-height: 38%; overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--floatShadowCss); }
  body.pmap .pd .mapdrv:empty { display: none; }
  body.pmap .pd .mapdrv.all { max-height: 62%; }
  body.pmap .pd .mapdrv .mapall { display: block; width: 100%; min-height: 46px; border: 0; border-top: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 15px; font-weight: 700; }
  body.pmap .pd #btnPasteOrder { display: none; }
}
