/* mobile.css: the platform layer that makes the workspace feel installed on a phone.
   Loaded last. Touch rules are gated by capability ((hover:none), (pointer:coarse)); layout rules by the 760px phone breakpoint used in styles.css.
   Owned by the mobile-native lane; see MOBILE.md. */

/* ---- every device ---- */
html{-webkit-tap-highlight-color:transparent;-webkit-text-size-adjust:100%;text-size-adjust:100%}
/* the app shell is not a document: no pull-to-refresh or rubber-band on the page itself */
html,body{overscroll-behavior:none}
/* 100% of html is the large viewport on iOS Safari; dvh follows the toolbar and the keyboard */
@supports (height:100dvh){html,body,.app{height:100dvh}}

/* controls: no 300ms double-tap wait, no long-press text selection or callout */
button,a,select,summary,label,[role=button],[role=tab],[data-go],[data-act],.nav,.tab,.conv,.w-row,.deal,.sheet-item,.chip,.tile,.list-row,.row{touch-action:manipulation}
button,[role=button],[role=tab],.nav,.tab,.sheet-item,.chip,.btn,.seg,.tabs,.side,.top,.tabbar,.sheet-h,.phead-chip,.pill,.stamp{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
/* content stays selectable: messages, notes, briefs, inputs */
input,textarea,[contenteditable],.msg,.bubble{-webkit-user-select:text;user-select:text}

/* ---- touch screens: hover must not stick after a tap ---- */
@media (hover:none){
  /* every shell hover tints with var(--hover); on touch that tint would stay on after the tap, so it becomes nothing */
  :root:not(#_){--hover:transparent}
  .btn.primary:hover,.btn.st.fill:hover{filter:none}
  .btn.st:hover,.btn.ai:hover,.btn.danger:hover{background:var(--surface)}
  .tile:hover,.deal:hover{border-color:var(--line)}
  .search:hover{border-color:transparent}
  /* view hover variables (--a-hv, --o-hover, --mk-hov) derive from --hover, so they follow; the inbox tints with --soft directly */
  .w-row:not([aria-current="true"]):hover,.w-bundle:hover,.w-ib:hover,.w-x:hover,.w-task:hover,.w-tr:hover td,.w-menu button:hover:not(:focus-visible){background:transparent}

  /* feedback on press instead, shown immediately on touch-down */
  :is(.conv,.w-row,.w-bundle,.w-task,.w-ib,.mk-row,.ops-row,.ops-chip,.af-turn,.row,.list-row,.nitem,.sri,.nav,.filters button,button.chip,.iconbtn,.btn.ghost,.sheet-item,.tab):active{background:var(--press);transition:none}
  :is(.tile,.deal):active{background:var(--press);border-color:var(--line-2);transition:none}
  .btn:active{background:var(--press)}
  .btn.primary:active,.btn.st.fill:active{filter:brightness(.9)}
  /* a small physical give on the big touch targets; scale only, so it stays on the compositor */
  :is(.btn,.sheet-item,.deal,.tile,.tab svg){transition:transform .16s cubic-bezier(.32,.72,0,1)}
  :is(.btn,.sheet-item,.deal,.tile):active{transform:scale(.97)}
  .tab:active svg{transform:scale(.9)}
}

/* ---- phone layout ---- */
@media (max-width:760px){
  /* 16px stops iOS from zooming into a focused field; zoom itself stays allowed */
  :root :is(input:not([type=checkbox]):not([type=radio]):not([type=range]),textarea,select,.inp){font-size:16px}

  /* scroll panes keep their scroll to themselves (no scroll chaining to the shell), with momentum */
  .view,.convlist,.chat,.ctx,.drawer,.sheet,.modal,.notif,.sres,.thread,.w-thread{overscroll-behavior:contain;-webkit-overflow-scrolling:touch}
  /* horizontal strips scroll sideways only and snap gently */
  .seg,.w-actionbar,.tabs{overscroll-behavior-x:contain;touch-action:pan-x pan-y}

  /* 44px touch targets for the shell's icon buttons and controls */
  .top .iconbtn,.top .btn,.sheet-h .iconbtn,.modal-h .btn.icon,.drawer .iconbtn{min-width:44px;min-height:44px}
  .btn{min-height:40px}
  .btn.sm{min-height:36px}
  button.chip,.seg button{min-height:36px}
  /* 32px icon buttons inside views keep their drawn size but get a 44px invisible hit area */
  @media (pointer:coarse){
    .w-ib,.w-x,.view .iconbtn,.view .btn.icon{position:relative}
    .w-ib::after,.w-x::after,.view .iconbtn::after,.view .btn.icon::after{content:"";position:absolute;inset:-6px}
    .w-x::after{inset:-10px}
  }

  /* bottom tab bar: a soft pill behind the active icon, like a native tab bar; hairline over content */
  .tabbar{background:color-mix(in srgb,var(--bg) 92%,transparent);-webkit-backdrop-filter:saturate(1.4) blur(14px);backdrop-filter:saturate(1.4) blur(14px)}
  .tab{isolation:isolate}
  .tab::before{content:"";position:absolute;top:4px;left:50%;width:48px;height:26px;margin-left:-24px;border-radius:13px;background:var(--act-soft);z-index:-1;opacity:0;transform:scaleX(.6);transition:opacity .18s ease-out,transform .22s cubic-bezier(.32,.72,0,1)}
  .tab[aria-current="page"]::before{opacity:1;transform:none}

  /* the More sheet: slides up from the bottom edge, grip is a real handle, never taller than the screen */
  .sheet{max-height:min(86dvh,calc(100dvh - 48px));overflow-y:auto;animation:m-up .28s cubic-bezier(.32,.72,0,1)}
  .sheet-grip{position:relative;width:40px;height:5px;margin-bottom:var(--s1)}
  .sheet-grip::after{content:"";position:absolute;inset:-12px -40px}

  /* modals become bottom sheets on a phone: thumb-reachable, slide from the edge they belong to */
  .scrim:has(> .modal){align-items:flex-end;justify-content:stretch!important}
  .modal{width:100%;max-width:none;margin:auto 0 0;max-height:calc(100dvh - 40px - env(safe-area-inset-top,0px));border-radius:var(--r3) var(--r3) 0 0;border-width:1px 0 0;padding-bottom:calc(var(--s4) + env(safe-area-inset-bottom,0px));animation:m-up .28s cubic-bezier(.32,.72,0,1)}
  .modal::before{content:"";display:block;width:40px;height:5px;border-radius:3px;background:var(--line-2);margin:-4px auto 0;flex:none}

  /* the drawer ("Why") comes in from the right edge, full height, clear of the notch and home bar */
  .drawer{padding-top:calc(var(--s4) + env(safe-area-inset-top,0px));padding-bottom:calc(var(--s4) + env(safe-area-inset-bottom,0px))}

  /* content and the sticky staff action bar clear the side insets in landscape */
  .view:not(.full){padding-left:max(var(--s4),env(safe-area-inset-left,0px));padding-right:max(var(--s4),env(safe-area-inset-right,0px))}
  .w-actionbar{padding-bottom:8px}

  /* toasts sit above the tab bar, not under the home indicator */
  .toast{bottom:calc(68px + env(safe-area-inset-bottom,0px))}
}

/* landscape phone: the tab bar and top bar respect the side insets */
@media (max-width:960px) and (max-height:500px) and (orientation:landscape){
  .tabbar{padding-left:max(4px,env(safe-area-inset-left,0px));padding-right:max(4px,env(safe-area-inset-right,0px))}
  .top{padding-left:max(var(--s4),env(safe-area-inset-left,0px));padding-right:max(var(--s2),env(safe-area-inset-right,0px))}
  /* full-bleed views (inbox, pipeline board) have no padding of their own, so they clear the notch here */
  .view.full{padding-left:env(safe-area-inset-left,0px);padding-right:env(safe-area-inset-right,0px)}
}

@keyframes m-up{from{transform:translateY(100%)}to{transform:none}}
@media (prefers-reduced-motion:reduce){
  .sheet,.modal{animation:none}
  .tab::before,:is(.btn,.sheet-item,.deal,.tile,.tab svg){transition:none}
  :is(.btn,.sheet-item,.deal,.tile):active,.tab:active svg{transform:none}
}
/* phone: every select is a 40px touch target, whatever compact size its view uses on desktop */
@media (max-width:760px){select:not([multiple]):not([size]){min-height:40px}}
/* phone: every inline text button (.lnk) gets the apron, so 15–20px links are thumb-sized */
@media (max-width:760px){.lnk{position:relative}.lnk::after{content:"";position:absolute;inset:-10px -4px}}
/* page-head actions on phone: when they wrap under the chips they start at the left edge, where the thumb and the eye already are (they were pushed right by margin-left:auto) */
@media (max-width:760px){.phead-a{margin-left:0}}
/* filter chips: 32px tall on phone plus a 3px apron = 38px target, no overlap across the 6px wrap gap */
@media (max-width:760px){.filters button{height:32px;position:relative}.filters button::after{content:"";position:absolute;inset:-3px}}

/* ---- mobile shell pass (2 Nov): less header, iOS-style collapse ----
   The page title already lives in the top bar on phone, so the page head (chips + actions) is a second row that simply scrolls away,
   while a hub's tab row pins to the top of the scroller: the large-title collapse without any JS. */
@media (max-width:760px){
  :root{--top-h:44px}
  .top{min-height:calc(44px + env(safe-area-inset-top,0px))}
  /* top-bar primary is a tinted glyph like an iOS nav-bar action, not a filled 44px block jammed into the corner */
  .top #logtp{background:none;border:0;box-shadow:none;color:var(--act);min-width:44px;min-height:44px;padding:0}
  .top #logtp svg{width:22px;height:22px}
  .top #logtp:active{background:var(--hover)}
  .view:not(.full){padding-top:8px;row-gap:8px}
  .view:not(.full)>.phead{height:auto;min-height:40px;padding-bottom:4px}
  .view:not(.full)>.seg{position:sticky;top:-8px;z-index:6;box-shadow:0 -8px 0 var(--bg),0 6px 8px -6px color-mix(in srgb,var(--ink) 18%,transparent)}
}
@media (max-width:760px){
  /* a hub head whose chips are folded away on phone and that has no button left is an empty 40px row: drop it, the tab row is the header */
  .view:not(.full)>.phead:has(+ .seg[aria-label="Impact"]):not(:has(.phead-a button,.phead-a a,.phead-a select)){display:none}
}
@media (max-width:760px){
  /* primary actions are 44px on phone wherever they sit; a head holding one grows to fit it */
  #view .btn.primary{min-height:44px}
  /* secondary controls: 32px minimum, or a transparent apron that extends the hit area without moving layout */
  :is(.t-info,.w-sc-pt,.inv-k,.ag-node){position:relative}
  :is(.t-info,.w-sc-pt,.vb-fab,.inv-k,.inv-more,.ag-node,.inv-nrb)::after{content:"";position:absolute;inset:-6px}
  .t-info::after,.w-sc-pt::after{inset:-10px}
  #view .btn.sm.icon{min-width:36px}
  .ag-sort{min-height:32px}
  #view input[type=checkbox]{width:20px;height:20px;margin:6px}
  #view .ops-inp{min-height:36px}
}
@media (max-width:760px){
  /* safety net for page heads nested inside a view's own wrapper (.w-doc, .ops-doc…): the same one-line, sideways-scrolling head as the top-level rule, so chips can never widen the page */
  #view .phead{max-width:100%;min-width:0;flex-wrap:nowrap;overflow-x:auto;overflow-y:hidden;scrollbar-width:none;overscroll-behavior-x:contain}
  #view .phead::-webkit-scrollbar{display:none}
  #view .phead>*{flex:none}
}
@media (max-width:760px){
  /* tab rows fade only on the side that hides more tabs (data-edge set by core.js) */
  .seg[data-edge="r"]{-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 28px),transparent);mask-image:linear-gradient(90deg,#000 calc(100% - 28px),transparent)}
  .seg[data-edge="l"]{-webkit-mask-image:linear-gradient(90deg,transparent,#000 28px);mask-image:linear-gradient(90deg,transparent,#000 28px)}
  .seg[data-edge="lr"]{-webkit-mask-image:linear-gradient(90deg,transparent,#000 28px,#000 calc(100% - 28px),transparent);mask-image:linear-gradient(90deg,transparent,#000 28px,#000 calc(100% - 28px),transparent)}
  .seg[data-edge=""]{-webkit-mask-image:none;mask-image:none}
}
/* quiet secondary/destructive action that sits beside bordered buttons: same 32px box and baseline, no border, muted ink; .danger tints it */
.btn.quiet{border-color:transparent;background:none;box-shadow:none;color:var(--muted)}
.btn.quiet:hover{color:var(--ink);background:var(--hover)}
.btn.quiet.danger{color:var(--bad)}.btn.quiet.danger:hover{background:var(--bad-bg)}
@media (max-width:760px){
  /* P1 (founder: "huge header space"): on phone every page head is one compact row. Title is in the top bar; count chips and the (i) are meta that the content repeats, so they go; secondary head buttons shrink to quiet 32px; a head left with nothing in it disappears */
  #view .phead .phead-chip,#view .phead .phead-i{display:none}
  #view .phead{min-height:0;padding-block:0 4px;gap:6px}
  #view .phead .phead-a{gap:6px}
  #view .phead .phead-a .btn:not(.primary){min-height:32px;height:32px;padding-inline:10px;font-size:13px}
  #view .phead:not(:has(.phead-a :is(button,a,select,input):not([hidden]))):not(:has(+ .seg)){display:none}
}
@media (max-width:760px){
  /* the page's own primary lives in the top bar on phone (core.js syncTopAct); hide the in-page copy and the generic "+" so there is one */
  .app.has-topact #view .phead .btn.primary{display:none}
  .app.has-topact .top #logtp{display:none}
  .top .topact{color:var(--act);min-width:44px;min-height:44px}
  .top .topact svg{width:22px;height:22px}
}
.top .topact[hidden]{display:none}

/* phone page-action slot (core.js syncTopAct): "+", "⋯" menu, page search over the top bar */
.topslot{display:none}
@media (max-width:760px){
  .topslot{display:flex;align-items:center;position:relative;order:9}
  .topslot .topact{color:var(--act);min-width:44px;min-height:44px}
  .topslot .topact svg{width:22px;height:22px}
  .topslot .topact[hidden]{display:none}
  .app.has-topact .top #logtp{display:none}
  .app.has-proxy #view .phead .btn.primary{display:none}
  .topmenu{position:absolute;top:calc(100% + 4px);right:0;min-width:200px;padding:4px;background:var(--surface);border:1px solid var(--line);border-radius:var(--r3,12px);box-shadow:var(--shadow-3);z-index:60;display:flex;flex-direction:column}
  .topmenu[hidden]{display:none}
  .topmenu button{all:unset;box-sizing:border-box;min-height:44px;padding:0 12px;border-radius:8px;font:500 15px var(--body);color:var(--ink);display:flex;align-items:center;cursor:pointer}
  .topmenu button:active,.topmenu button:focus-visible{background:var(--hover)}
  .topmenu button.danger{color:var(--bad)}
  .psearch{position:absolute;inset:env(safe-area-inset-top,0px) 0 0 0;display:flex;align-items:center;gap:8px;padding:0 4px 0 16px;background:var(--bg);z-index:61}
  .psearch[hidden]{display:none}
  .psearch>svg{width:18px;height:18px;color:var(--muted);flex:none}
  .psearch input{flex:1;min-width:0;height:36px;border:0;border-radius:10px;background:var(--hover);padding:0 12px;font:16px var(--body);color:var(--ink)}
  .psearch input:focus{outline:2px solid var(--act-soft,var(--act));outline-offset:0}
  .top{position:relative}
}
@media (max-width:760px){
  /* phone-critic round 1 */
  /* 1. every horizontal strip gets the same edge cue as .seg (data-edge set by core.js segEdges) */
  :is(.t-ph-c,.w-views,.w-lfilt,.vb-pchips,.inv-fl,.ops-chips,.af-chips,.ag-lamps,.lib-strip,[data-strip])[data-edge="r"]{-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 24px),transparent);mask-image:linear-gradient(90deg,#000 calc(100% - 24px),transparent)}
  :is(.t-ph-c,.w-views,.w-lfilt,.vb-pchips,.inv-fl,.ops-chips,.af-chips,.ag-lamps,.lib-strip,[data-strip])[data-edge="l"]{-webkit-mask-image:linear-gradient(90deg,transparent,#000 24px);mask-image:linear-gradient(90deg,transparent,#000 24px)}
  :is(.t-ph-c,.w-views,.w-lfilt,.vb-pchips,.inv-fl,.ops-chips,.af-chips,.ag-lamps,.lib-strip,[data-strip])[data-edge="lr"]{-webkit-mask-image:linear-gradient(90deg,transparent,#000 24px,#000 calc(100% - 24px),transparent);mask-image:linear-gradient(90deg,transparent,#000 24px,#000 calc(100% - 24px),transparent)}
  /* 2. a head whose children are all hidden still took 5px + 4px padding */
  #view .phead:empty,#view .phead:not(:has(> :not([hidden]):not(.phead-chip):not(.phead-i):not(h2))):not(:has(+ .seg)){display:none}
  /* 4. back chevron on detail pages */
  .top .topback{min-width:44px;min-height:44px;margin-left:-12px;color:var(--act)}
  .top .topback[hidden]{display:none}
  /* 5. sheet and pane close buttons reach 44 */
  :is([role=dialog],.inv-pan,.w-tp,.drawer,.sheet) :is([aria-label="Close"],[aria-label^="Close "],.w-ib[aria-label*="lose"]){min-width:44px;min-height:44px}
  /* 6. small chips get a vertical apron */
  :is(.t-chip,button.chip,a.chip){position:relative}
  :is(.t-chip,button.chip,a.chip)::after{content:"";position:absolute;inset:-8px 0}
  /* 7. no extra 8px above a page that opens with a strip */
  #view:not(.full):has(> :is(.seg,[data-strip]):first-child){padding-top:0}
}
@media (min-width:761px){.top .topback{display:none}}
@media (max-width:760px){#view .phead.is-empty{display:none}}
@media (max-width:760px){
  /* phone-critic round 2 */
  /* low-specificity default so a view's own phone padding (e.g. #view[data-route="feed"]{padding-top:0}) still wins */
  .view.view:not(.full){padding-top:4px}
  :is(.w-tabs)[data-edge="r"]{-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 24px),transparent);mask-image:linear-gradient(90deg,#000 calc(100% - 24px),transparent)}
  :is(.w-tabs)[data-edge="l"]{-webkit-mask-image:linear-gradient(90deg,transparent,#000 24px);mask-image:linear-gradient(90deg,transparent,#000 24px)}
  :is(.w-tabs)[data-edge="lr"]{-webkit-mask-image:linear-gradient(90deg,transparent,#000 24px,#000 calc(100% - 24px),transparent);mask-image:linear-gradient(90deg,transparent,#000 24px,#000 calc(100% - 24px),transparent)}
  /* every close control in sheets, panes and dialogs is 44px, whatever its label wording */
  :is([role=dialog],.inv-pan,.w-tp,.drawer,.sheet,.modal) :is(button[aria-label^="Close"],.inv-x[data-act="invClose"],.w-ctx-x){min-width:44px;min-height:44px}
}
