/* Mobile layout lives here so the desktop rules stay readable. The breakpoint follows the space
   the controls need, not a named device. */
.mobileOnly { display: none !important; }
#moreViews{display:contents}
.filterPanel { display: contents; }
.mobileMenu {
  width: 260px; margin: 0; padding: 10px; inset: var(--topH, 64px) 10px auto auto;
  color: var(--fg); background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 36px var(--theme-scrim);
}
.mobileMenu:popover-open { display: flex; flex-direction: column; gap: 7px; }
.mobileMenu button { text-align: left; }
.mobileAccount { display: flex; align-items: center; gap: 8px; padding: 5px 3px 10px; }
.mobileAccount b { flex: 1; }
.count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding-inline: 5px;
  margin-left: 4px; border-radius: 99px; background: var(--accent2); color: var(--theme-fg); font-size: 11px;
}

@media (max-width: 700px), (max-height: 500px) and (pointer: coarse) {
  :root {
    --safeTop: env(safe-area-inset-top, 0px); --safeRight: env(safe-area-inset-right, 0px);
    --safeBottom: env(safe-area-inset-bottom, 0px); --safeLeft: env(safe-area-inset-left, 0px);
    --mobileNavH: calc(74px + var(--safeBottom));
  }
  /* Clip horizontal overflow without creating a body scroll container: sticky headers and
     status tabs must follow the document scroll on mobile. */
  html { min-width: 0; overflow-x: clip; }
  body {
    min-width: 0; padding: 0 var(--safeRight) var(--mobileNavH) var(--safeLeft); overflow-x: clip;
  }
  input, select, textarea { font-size: 16px; }
  button, [role="button"] { min-height: 44px; }
  .mobileOnly:where(:not(.hidden)) { display: initial !important; }
  .mobileOnly.hidden { display: none !important; }

  /* Two compact rows. Navigation is fixed at the bottom and does not add to --topH. */
  header#top {
    display: grid; grid-template-columns: 44px minmax(0, 1fr) auto auto auto;
    gap: 8px; align-items: center; padding: calc(8px + var(--safeTop)) 10px 8px;
  }
  header#top > .spacer, header#top > #findBtn, header#top > #refreshBtn { display: none; }
  header#top:has(#fProject.hidden) { grid-template-columns: minmax(0, 1fr) auto auto auto; }
  .workspaceIdentity { gap: 8px; }
  #top .brand { width: 44px; justify-content: center; }
  #top .brandName { display: none; }
  #top .organizationLink { max-width: 100%; padding: 8px; font-size: 12px; gap: 6px; }

  #fProject { width: 100%; min-width: 0; height: 44px; }
  #newBtn { width: 44px; padding: 0; font-size: 0; }
  #newBtn::before { content: '+'; font-size: 24px; line-height: 1; }
  .me { margin: 0; gap: 0; }
  .me > :not(#bellBtn) { display: none; }
  #bellBtn, #mobileMenuBtn { width: 44px; padding: 0; }
  #mobileMenuBtn { display: block !important; font-size: 0; }
  #mobileMenuBtn::before { content: '⋮'; font-size: 24px; }

  .views {
    display: grid !important; grid-template-columns: repeat(5,minmax(0,1fr));
    position: fixed; z-index: 30; inset: auto calc(8px + var(--safeRight)) calc(8px + var(--safeBottom)) calc(8px + var(--safeLeft)); height: 58px;
    padding: 0 calc(4px + var(--safeRight)) var(--safeBottom) calc(4px + var(--safeLeft)); background: var(--panel);
    border-top: 1px solid var(--line); box-shadow: 0 -5px 18px var(--theme-scrim);
  }
  .views button, .views button:first-child, .views button:last-child {
    min-width: 0; min-height: 50px; padding: 5px 2px; border: 0; border-radius: 0;
    background: transparent; font-size: 12px; line-height: 1.2; white-space: nowrap;
  }
  .views button.on { background: var(--theme-hover); color: var(--accent); box-shadow: inset 0 3px var(--accent); }
  .views button.on:hover { background: var(--theme-hover); color: var(--accent); }
  #moreViews{display:none;position:fixed;inset:auto calc(12px + var(--safeRight)) calc(var(--mobileNavH) + 8px) auto;margin:0;padding:10px;width:220px;max-width:calc(100vw - 24px);background:var(--panel);color:var(--fg);border:1px solid var(--line);border-radius:12px;box-shadow:0 4px 20px var(--theme-scrim)}
  #moreViews:popover-open{display:flex;flex-direction:column;gap:6px}
  .views #moreViewsBtn{display:inline-flex!important}
  #moreViews button{flex-direction:row;justify-content:flex-start;font-size:14px;padding:10px}

  .filters {
    grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px; padding: 0; min-width: 0;
  }
  #q { width: 100%; min-width: 0; max-width: none; height: 44px; }
  #filterToggle { display: block !important; white-space: nowrap; }
  .filterPanel {
    display: flex; flex-direction: column; gap: 10px; position: fixed; z-index: 42;
    inset: auto 0 var(--mobileNavH); max-height: min(76dvh, 640px); overflow-y: auto;
    padding: 14px calc(14px + var(--safeRight)) calc(14px + var(--safeBottom))
      calc(14px + var(--safeLeft));
    background: var(--panel); border: 1px solid var(--line); border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 36px var(--theme-scrim); transform: translateY(calc(100% + var(--mobileNavH)));
    visibility: hidden; pointer-events: none;
    transition: transform 240ms var(--ease-drawer), visibility 240ms allow-discrete;
  }
  .filterPanel.open { transform: none; visibility: visible; pointer-events: auto; }
  .filterPanel select { width: 100%; min-height: 46px; max-width: none; }
  .filterPanel #boardSort { max-width: none; }
  .filterPanel .chk { min-height: 44px; font-size: 14px; }
  .filterPanel .chk input { width: 20px; height: 20px; }
  .filterSheetHead { display: flex !important; align-items: center; gap: 10px; }
  .filterSheetHead strong { flex: 1; font-size: 16px; }
  .filterSheetHead .x { width: auto; }
  .filterSheetFoot { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px; }
  .filterScrim {
    display: block !important; position: fixed; z-index: 41; inset: 0 0 var(--mobileNavH);
    background: var(--theme-scrim); opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity 180ms ease, visibility 180ms allow-discrete;
  }
  .filterScrim.open { opacity: 1; visibility: visible; pointer-events: auto; }
  .activeFilters {
    grid-column: 1 / -1; display: flex !important; gap: 6px; overflow-x: auto; min-width: 0;
    scrollbar-width: none;
  }
  .activeFilters:empty { display: none !important; }
  .activeFilters button { min-height: 44px; padding: 4px 9px; white-space: nowrap; font-size: 12px; }

  .mobileMenu {
    width: min(360px, calc(100vw - 20px - var(--safeLeft) - var(--safeRight)));
    max-height: 70dvh; overflow-y: auto;
    inset: auto calc(10px + var(--safeRight)) calc(var(--mobileNavH) + 10px); border-radius: 14px;
  }
  .mobileMenu button { min-height: 46px; }

  /* The bar remains useful at a glance. Its wordy explanation is a disclosure. */
  .meter { gap: 7px; padding: 9px 10px 7px; }
  .meter .bar { height: 44px; }
  .meterMobileRow { display: flex !important; align-items: center; gap: 8px; }
  .meterMobileRow span { flex: 1; }
  .meterMobileRow button { min-height: 44px; padding: 4px 9px; font-size: 12px; }
  .meter:not(.expanded) > .keys { display: none; }
  .meter .keys { gap: 8px; }
  .meter .keys > span:first-child { gap: 4px 10px; }
  .meter .keys .spacer { display: none; }
  .meter .keys select { width: 100%; min-height: 44px; font-size: 16px; }

  /* One column, one document scrollbar. Status tabs replace sideways hunting. */
  .boardTabs {
    display: flex !important; flex-wrap: nowrap; gap: 6px; position: sticky; top: var(--topH, 108px); z-index: 4;
    padding: 8px 10px; overflow-x: auto; background: var(--bg); border-bottom: 1px solid var(--line);
    scrollbar-width: thin; scrollbar-color: var(--line) transparent; scroll-padding-inline: 10px;
  }
  .boardTabs.hidden { display: none !important; }
  .boardTabs button { flex: 0 0 auto; min-height: 44px; padding: 5px 11px; white-space: nowrap; }
  .boardTabs button.on { color: var(--theme-fg); background: var(--accent2); border-color: var(--accent2); }
  .board { display: block; min-height: 0; padding: 10px; overflow: visible; }
  .board .col { display: none; width: 100%; max-height: none; }
  .board .col.mobileCurrent { display: flex; }
  .col .stack { overflow: visible; }
  .cardItem { cursor: pointer; padding: 11px; }
  .pickTarget {
    display: grid; place-items: center; flex: 0 0 44px; width: 44px; height: 44px;
    margin: -11px 0 -11px -11px;
  }
  .cardItem .pick { width: 20px; height: 20px; opacity: 1; }
  .cardMove { margin-left: auto; min-height: 44px; padding: 4px 9px; font-size: 12px; }

  .bulkBar {
    bottom: calc(var(--mobileNavH) + 8px); left: var(--safeLeft); right: var(--safeRight);
    width: calc(100vw - var(--safeLeft) - var(--safeRight) - 20px); max-height: 55dvh;
    overflow-y: auto; align-items: stretch; flex-wrap: wrap; padding: 12px;
  }
  .bulkBar > b { flex-basis: 100%; }
  .bulkBar select, .bulkBar input { flex: 1 1 45%; min-width: 0; min-height: 44px; }
  .bulkBar button { flex: 1; }
  .actionSheet { height: auto; max-height: 70dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .actionChoices { display: flex; flex-direction: column; gap: 8px; padding: 14px; }
  .actionChoices button { text-align: left; }

  /* Dense tree rows become readable blocks instead of one clipped sentence. */
  .treeView { padding: 0 10px calc(20px + var(--mobileNavH)); }
  .treeBar { top: var(--topH, 108px); flex-wrap: wrap; gap: 7px; }
  .treeBar button { flex: 1; min-height: 44px; }
  .treeBar #treeSummary { flex-basis: 100%; }
  .treeRow {
    flex-wrap: wrap; gap: 6px; min-height: 48px; padding: 9px;
    margin-left: calc(var(--d, 0) * 14px);
  }
  .treeRow .fold { width: 44px; min-height: 44px; flex: 0 0 44px; }
  .treeRow .t {
    flex: 1 1 calc(100% - 112px); overflow: visible; text-overflow: clip; white-space: normal;
    overflow-wrap: anywhere; line-height: 1.4;
  }
  .treeRow > .spacer { display: none; }
  .treeProg { flex: 1 1 100%; margin-left: 40px; flex-wrap: wrap; }
  .treeProg .pbar { flex: 1; min-width: 100px; }
  .treeRow .avatar { margin-left: auto; }

  .flowView { padding: 10px 10px calc(18px + var(--mobileNavH)); }
  .flowGrid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .flowCard { min-width: 0; padding: 12px; }
  .bigStats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .mini { flex-wrap: wrap; min-height: 44px; }
  .mini .t { flex: 1 1 calc(100% - 90px); }
  .mini > .spacer { display: none; }
  .flowDur { margin-left: auto; }

  /* Canvas tools use disclosures so the graph receives the phone viewport. */
  .depsView { inset: calc(var(--topH, 108px) + var(--meterH, 0px)) 0 var(--mobileNavH); }
  .depsOptions {
    display: block !important; position: absolute; z-index: 5; top: 8px; right: 8px;
    min-height: 44px; background: color-mix(in srgb,var(--theme-panel) 90%,transparent); backdrop-filter: blur(6px);
  }
  .depsBar {
    position: absolute; z-index: 7; inset: auto 8px 8px; display: flex; flex-direction: column;
    align-items: stretch; gap: 8px; max-height: min(70dvh, 620px); overflow-y: auto;
    padding: 12px; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 -12px 36px var(--theme-scrim);
    transform: translateY(calc(100% + 20px)); visibility: hidden; pointer-events: none;
    transition: transform 240ms var(--ease-drawer), visibility 240ms allow-discrete;
  }
  .depsBar.open { transform: none; visibility: visible; pointer-events: auto; }
  .depsBarHead { display: flex !important; align-items: center; gap: 8px; }
  .depsBarHead strong { flex: 1; }
  .depsBar button { min-height: 44px; white-space: nowrap; }
  .depsBar #depsSummary, .depsBar > .muted.small, .depsBar > .spacer { display: none; }
  .depsView:has(.depsBar.open) .depsOptions { display: none !important; }
  .depsKey { left: 8px; bottom: 8px; max-width: calc(100% - 118px); }
  .depsKey span:last-child { display: none; }
  .zoomKit { right: 8px; bottom: 8px; }
  .depsTouchCard {
    position: absolute; z-index: 5; inset: auto 8px 56px; display: grid; gap: 4px;
    padding: 10px 12px; background: color-mix(in srgb,var(--theme-panel) 95%,transparent); border: 1px solid var(--line); border-radius: 10px;
    box-shadow: 0 8px 28px var(--theme-scrim);
  }
  .depsTouchCard span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .depsTouchCard small { color: var(--muted); }
  .depsTouchCard button { margin-top: 5px; }
  .depsTouchCard.hidden { display: none; }

  .zoomKit button { min-height: 44px; min-width: 44px; }
  .mapView { inset: var(--topH, 108px) 0 var(--mobileNavH); }
  .mapOptions {
    display: block !important; position: absolute; z-index: 4; top: 8px; right: 8px;
    min-height: 44px; background: color-mix(in srgb,var(--theme-panel) 90%,transparent); backdrop-filter: blur(6px);
  }
  .mapPanelHead { display: flex !important; align-items: center; gap: 8px; }
  .mapPanelHead strong { flex: 1; }
  .mapPanelHead .x { min-height: 44px; }
  .mapView:has(.mapPanel.open) .mapOptions { display: none !important; }

  .mapPanel {
    position: absolute; inset: auto 8px 8px; width: auto; max-height: min(70dvh, 620px);
    overflow-y: auto; transform: translateY(calc(100% + 20px)); visibility: hidden; pointer-events: none;
    transition: transform 240ms var(--ease-drawer), visibility 240ms allow-discrete;
  }
  .mapPanel.open { transform: none; visibility: visible; pointer-events: auto; }
  .mapPanel .row { flex-wrap: wrap; }
  .mapTip {
    position: absolute; inset: auto 8px 64px; max-width: none; pointer-events: auto;
  }
  .mapTip .tipOpen { width: 100%; margin-top: 8px; }

  .mapTip.hidden { pointer-events: none; }
  /* Complex tasks own the phone viewport. */
  .sheet {
    width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; inset: 0; border-width: 0;
    border-radius: 0; overflow: hidden;
  }
  .sheet[open] { display: flex; flex-direction: column; }
  .sheet form { min-height: 0; height: 100%; display: flex; flex-direction: column; }
  .sheetHead {
    flex: none; min-height: 58px; padding: calc(10px + var(--safeTop))
      calc(12px + var(--safeRight)) 10px calc(12px + var(--safeLeft)); z-index: 2;
  }
  .sheetHead .x { min-width: 44px; }
  .sheetBody { flex: 1; min-height: 0; max-height: none; padding: 14px calc(12px + var(--safeRight)) 14px calc(12px + var(--safeLeft)); }
  .sheetFoot { flex: none; padding: 10px calc(12px + var(--safeRight)) calc(10px + var(--safeBottom)) calc(12px + var(--safeLeft)); }
  .sheetFoot button { flex: 1; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .grid2 .full { grid-column: auto; }
  .sheet .row { flex-wrap: wrap; }
  .sheet .row > input, .sheet .row > select { flex: 1 1 180px; min-width: 0; }
  .plain li { flex-wrap: wrap; }
  .sheet.actionSheet {
    height: auto; max-height: 70dvh; margin: auto 0 0; border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
  }
  .sheet.actionSheet .sheetHead { padding-top: 10px; }

  .finder {
    width: auto; max-height: min(78dvh, 680px); margin: 0;
    inset: auto var(--safeRight) var(--mobileNavH) var(--safeLeft);
    border-radius: 16px 16px 0 0; transform: none;
  }
  .finder:popover-open { display: flex; flex-direction: column; }
  .finderInput, .finderStatus, .findPinned { flex-shrink: 0; }
  .finderInput { gap: 6px; }
  .finderInput kbd { display: none; }
  .finderInput .finderClose { display: inline-grid; place-items: center; width: 44px; min-width: 44px; padding: 0; }
  .findResults { flex: 1; min-height: 0; max-height: none; overscroll-behavior-y: contain; }
  .findResult { grid-template-areas: "type key state" "title title title" "why why why"; grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px 8px; }
  .findResult .t { white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  .findPinned { flex-wrap: wrap; }
  .findPinned span { flex-basis: 180px; }
  .bell {
    width: min(calc(100vw - var(--safeLeft) - var(--safeRight)), 480px); max-height: 70dvh; margin: 0;
    inset: auto var(--safeRight) var(--mobileNavH) auto; border-radius: 16px 16px 0 0;
  }
  .help { display: none !important; }
  body.zen { padding-bottom: 0; }
  .mapView, .depsView { right: var(--safeRight); left: var(--safeLeft); }
  body.zen .mapView, body.zen .depsView {
    inset: var(--safeTop) var(--safeRight) var(--safeBottom) var(--safeLeft);
  }
}

@media (max-width: 430px) {
  .brandName { display: none; }
}

@media (hover: none), (pointer: coarse) {
  .unlink, .sheetHead .copy, .cardItem .pick { opacity: 1; }
}
