/* QuoteDesk — owner phone shell ("app feel")                                   v20261109a
 *
 * v20261109a (2026-11-09): the search-builds P3 button (a second
 * button.ib.fill.show-sm in the top bar — the phone palette trigger, an <svg>
 * child with no <span>) now matches the menu-button rules below unless they
 * name the avatar button exactly. The menu rules therefore target
 * button.ib.fill.show-sm:has(> span) (the avatar / menu button is the one
 * carrying a <span> of initials), and the P3 trigger is hidden on this shell:
 * the wide search box already becomes this shell's search button.
 *
 * Loaded AFTER the app stylesheet (/static/qd/assets/index-*.css). Written against the live
 * stylesheet sha256 60387a4f…04d2 and the live bundle sha256 5def4643…c672.
 *
 * Where it applies — all three must be true, otherwise nothing here does anything:
 *   1. the screen is a phone (max-width: 640px),
 *   2. the session is the owner's (the app puts .owner-desk on .shell),
 *   3. /static/owner_app.js has started (it sets html.qd-oa). If that script ever fails to
 *      load, the live owner layout is left exactly as it is today.
 *
 * What it does: the full desktop navigation (every link the owner has today) moves from a
 * permanent 184px column into a slide-over drawer; the phone bottom bar comes back; the top
 * bar becomes a clean app bar (menu, title, search, notifications); pages use the full width.
 * Desktop, tablet and every other role are untouched.
 */

/* Helpers created by owner_app.js live in <body>; they are inert unless the phone shell is on. */
.qd-oa-scrim,
.qd-oa-close,
.qd-oa-lang { display: none; }

@media (max-width: 640px) {

  /* ---------- 1. one column: the sidebar leaves the layout ---------- */
  html.qd-oa .shell.owner-desk {
    --top-h: 56px;
    grid-template-columns: minmax(0, 1fr);
  }

  /* ---------- 2. the sidebar becomes a slide-over drawer ---------- */
  html.qd-oa .shell.owner-desk .rail {
    display: flex;
    position: fixed;
    z-index: 64;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 336px);
    height: auto;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 12px calc(92px + var(--safe-b));
    gap: 2px;
    border-right: 1px solid var(--line);
    box-shadow: none;
    transform: translateX(-104%);
    visibility: hidden;
    transition: transform .28s var(--ease), box-shadow .28s var(--ease), visibility 0s linear .28s;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  html.qd-oa.qd-nav-open .shell.owner-desk .rail {
    transform: none;
    visibility: visible;
    box-shadow: var(--shadow-3);
    transition: transform .28s var(--ease), box-shadow .28s var(--ease), visibility 0s;
  }
  html.qd-oa .owner-desk .brandrow { padding: 4px 52px 16px 6px; }
  html.qd-oa .owner-desk .brandname { font-size: 19px; line-height: 22px; }
  html.qd-oa .owner-desk .brandsub { font-size: 12px; line-height: 15px; }
  html.qd-oa .owner-desk .rail > .btn.block { height: 52px; margin-bottom: 14px !important; font-size: 17px; }
  html.qd-oa .owner-desk .navlink {
    min-height: 50px;
    padding: 0 14px;
    gap: 14px;
    font-size: 16.5px;
    border-radius: 14px;
    -webkit-tap-highlight-color: transparent;
  }
  html.qd-oa .owner-desk .navlink svg { width: 22px; height: 22px; }
  html.qd-oa .owner-desk .navlink:active { background: var(--sunk); }
  html.qd-oa .owner-desk .navlink.on:active { background: var(--ink); }
  html.qd-oa .owner-desk .navsect { padding: 20px 14px 6px; }
  html.qd-oa .owner-desk .navfoot { padding-top: 12px; }

  /* dimmed page behind the drawer */
  .qd-oa-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 63;
    background: rgba(22, 18, 14, .5);
    opacity: 0;
    visibility: hidden;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    transition: opacity .28s var(--ease), visibility 0s linear .28s;
  }
  html.qd-nav-open .qd-oa-scrim {
    opacity: 1;
    visibility: visible;
    transition: opacity .28s var(--ease), visibility 0s;
  }
  html.qd-nav-open,
  html.qd-nav-open body { overflow: hidden; }

  /* close button, pinned to the drawer's top-right corner */
  .qd-oa-close {
    display: inline-flex;
    position: fixed;
    z-index: 66;
    top: calc(12px + env(safe-area-inset-top, 0px));
    left: calc(min(86vw, 336px) - 56px);
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 12px;
    background: var(--surface);               /* solid, so menu rows scrolling underneath never collide with it */
    color: var(--ink-2);
    opacity: 0;
    visibility: hidden;
    -webkit-tap-highlight-color: transparent;
    transition: opacity .2s var(--ease), visibility 0s linear .2s;
  }
  .qd-oa-close svg { width: 24px; height: 24px; }
  .qd-oa-close:active { background: var(--sunk); }
  html.qd-nav-open .qd-oa-close { opacity: 1; visibility: visible; transition: opacity .2s var(--ease) .1s, visibility 0s; }

  /* language switch pinned to the drawer's foot (the EN/ES pill leaves the phone top bar) */
  .qd-oa-lang {
    display: flex;
    position: fixed;
    z-index: 65;
    left: 0;
    bottom: 0;
    width: min(86vw, 336px);
    box-sizing: border-box;
    padding: 12px 12px calc(12px + var(--safe-b));
    align-items: center;
    background: var(--surface);
    border-top: 1px solid var(--line);
    transform: translateX(-104%);
    visibility: hidden;
    transition: transform .28s var(--ease), visibility 0s linear .28s;
  }
  html.qd-nav-open .qd-oa-lang { transform: none; visibility: visible; transition: transform .28s var(--ease), visibility 0s; }
  .qd-oa-lang .seg { display: grid; width: 100%; }
  .qd-oa-lang .seg button { min-height: 44px; }

  /* ---------- 3. the top bar becomes an app bar: menu · title · search · notifications ---------- */
  html.qd-oa .owner-desk .topbar { padding: calc(6px + env(safe-area-inset-top, 0px)) 6px 6px 4px; gap: 2px; min-height: var(--top-h); }

  /* menu button = the app's own round "avatar / menu" button, drawn as a hamburger and sent to the left.
     It is the button.ib.fill.show-sm carrying a <span> (the initials); the P3 palette trigger
     carries an <svg> instead and must never pick up this styling. */
  html.qd-oa .owner-desk .topbar > button.ib.fill.show-sm:has(> span) {
    display: inline-flex !important;
    order: -3;
    background: transparent;
    border-color: transparent;
    color: var(--ink);
    -webkit-tap-highlight-color: transparent;
  }
  html.qd-oa .owner-desk .topbar > button.ib.fill.show-sm:has(> span) > span { display: none; }
  html.qd-oa .owner-desk .topbar > button.ib.fill.show-sm:has(> span)::before {
    content: "";
    width: 20px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
    box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
  }
  html.qd-oa .owner-desk .topbar > button.ib.fill.show-sm:has(> span):active { background: var(--sunk); }

  /* the search-builds P3 phone palette trigger (button.ib.fill.show-sm with an <svg> child):
     a duplicate on this shell — the wide search box below already becomes the search button —
     and left visible it renders as a second, merged hamburger+magnifier control at the left. */
  html.qd-oa .owner-desk .topbar > button.ib.fill.show-sm:has(> svg) { display: none !important; }

  /* inside a job / estimate / search: a back arrow replaces the menu button */
  html.qd-oa .owner-desk .topbar > button.ib.show-sm:not(.fill) {
    display: inline-flex !important;
    order: -3;
    color: var(--ink);
  }
  html.qd-oa .owner-desk .topbar:has(> button.ib.show-sm:not(.fill)) > button.ib.fill.show-sm:has(> span) { display: none !important; }

  /* title (the app's own phone title, switched back on) */
  html.qd-oa .owner-desk .topbar > .hello.show-sm {
    display: flex !important;
    order: -2;
    flex: 1 1 0;
    min-width: 0;
    padding-left: 4px;
  }
  html.qd-oa .owner-desk .topbar > h1.show-sm {
    display: block !important;
    order: -2;
    flex: 1 1 0 !important;
    min-width: 0;
    padding-left: 8px !important;
  }
  html.qd-oa .owner-desk .page .hello.hide-sm { display: none !important; }   /* the greeting lives in the app bar now */

  /* search: the wide bar becomes a search button (still opens the same search-everything panel) */
  html.qd-oa .owner-desk .topbar > button.search.hide-sm {
    display: inline-flex !important;
    order: 5;
    flex: none !important;
    width: 44px;
    min-width: 44px;
    height: 44px !important;
    padding: 0;
    gap: 0;
    justify-content: center;
    border-color: transparent;
    background: transparent;
    border-radius: 12px;
    -webkit-tap-highlight-color: transparent;
  }
  html.qd-oa .owner-desk .topbar > button.search.hide-sm > :not(svg) { display: none !important; }
  html.qd-oa .owner-desk .topbar > button.search.hide-sm > svg { color: var(--ink); width: 24px; height: 24px; }
  html.qd-oa .owner-desk .topbar > button.search.hide-sm:active { background: var(--sunk); }

  /* notifications: same button, quieter frame */
  html.qd-oa .owner-desk .topbar > button.ib.fill:not(.show-sm):not(.shield) {
    order: 6;
    background: transparent;
    border-color: transparent;
  }
  html.qd-oa .owner-desk .topbar > button.ib.fill:not(.show-sm):not(.shield):active { background: var(--sunk); }

  /* the rest of the desktop bar is moved into the drawer or dropped on a phone */
  html.qd-oa .owner-desk .topbar > .grow.hide-sm,
  html.qd-oa .owner-desk .topbar > span.hide-sm,
  html.qd-oa .owner-desk .topbar > .langhost { display: none !important; }

  /* ---------- 4. pages use the full width again ---------- */
  html.qd-oa .owner-desk .page {
    padding: 4px 16px calc(var(--dock-h) + var(--tray-h) + 28px + var(--safe-b));
    gap: 16px;
  }
  html.qd-oa .owner-desk .card.pad,
  html.qd-oa .owner-desk .cfg-sec { padding: 16px; }
  html.qd-oa .owner-desk .card-h,
  html.qd-oa .owner-desk .card-b { padding: 14px 16px; }
  html.qd-oa .owner-desk .item { padding: 10px 14px; }
  html.qd-oa .owner-desk .kpis,
  html.qd-oa .owner-desk .grid-2,
  html.qd-oa .owner-desk .grid-3 { gap: 12px; }
  html.qd-oa .owner-desk .today-grid,
  html.qd-oa .owner-desk .est-layout { gap: 22px; }

  /* a page's title/description row with an action button: description on top, button under it */
  html.qd-oa .owner-desk .page > .row.sp:first-child:has(> .btn) { flex-wrap: wrap; align-items: stretch; row-gap: 12px; }
  html.qd-oa .owner-desk .page > .row.sp:first-child:has(> .btn) > :first-child { flex: 1 1 100%; min-width: 0; }
  html.qd-oa .owner-desk .page > .row.sp:first-child:has(> .btn) > .btn { flex: 1 1 100%; }

  /* ---------- 5. the bottom bar comes back, and everything that floats rides above it ---------- */
  html.qd-oa .owner-desk .dock { display: grid; }
  html.qd-oa .owner-desk .tray {
    left: 10px;
    right: 10px;
    width: auto;
    bottom: calc(var(--dock-h) + 8px + var(--safe-b));
  }
  html.qd-oa .owner-desk .toasts { bottom: calc(var(--dock-h) + var(--tray-h) + 22px + var(--safe-b)); }
  html.qd-oa .owner-desk .dq-bar { bottom: calc(var(--dock-h) + 8px + var(--safe-b)); }
  html.qd-oa .owner-desk .dq-form { padding-bottom: calc(var(--dock-h) + 204px + var(--safe-b)); }
  html.qd-oa .owner-desk .mobilebar { bottom: calc(var(--dock-h) + var(--safe-b)); padding-bottom: 10px; }
}

/* six bottom-bar items on the narrowest phones: a touch smaller so "Scheduling" never touches the screen edge */
@media (max-width: 380px) {
  html.qd-oa .owner-desk .dock .dk .dkl { font-size: 10.5px; }
}
